1

I've been using javascript to access to libraries in a site, but now I want to get the value of a custom field in a project.

I've been looking to do this but I've found nothing, clientcontext does not seem to have any way to access a project's data and I've found ProjectContext, it seems the way to go, but haven't found any example.

Anyone can point me out to the right direction?

1

I finally found a blog that got the answer, my problem was the same the autor had.

Here's the link: Sharepoint/Project Server App with javascript and Web Part

And here the code I developed in case someone else needs to do the same I needed:

<script src="../SiteAssets/scripts/jquery-1.11.2.min.js" type="text/javascript"></script> 
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/ps.js"></script>


<script type="text/javascript">

var contexto;
var proyectos;  
var arr_proy; 


    function init() {       

        contexto = PS.ProjectContext.get_current()
        console.log(contexto); 

        proyectos = contexto.get_projects();
        console.log(proyectos); 

        contexto.load(proyectos);
        console.log('Carga');
        contexto.executeQueryAsync(Function.createDelegate(this, this.Exito), Function.createDelegate(this, this.Error));

    }

    init(); 

    function Exito() {

        console.log('Exito');

        for(i = 0; i < proyectos.get_count(); i++) 
        {
            console.log(proyectos.get_item(i));
            console.log(proyectos.get_item(i).get_name());          
        }

    }

    function Error() {
        alert('Error'); 
    }

</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.