Read Project Online Project data using JSOM
Hello,
In this article, I’m going to discuss about reading Project Online Project Data using JSOM (JavaScript Object Model) with a simple code.
First create a .js file with the below code then upload it to the document library on the PWA tenant. Add it to a content editor web part of the Project Center page.
Add the below links to make use of the existing SharePoint and Project online APIs.
script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.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 projectContext; var custom_Fields;</span> var Allprojects;</span> jQuery(document).ready(function () { SP.SOD.executeOrDelayUntilScriptLoaded(ReadProjectsWithCustomFields, "PS.js"); }); //Read project data from the Project context object and loop through each project function ReadProjectsWithCustomFields() { var projectContext = PS.ProjectContext.get_current(); var Allprojects = projectContext.get_projects(); projectContext.load(Allprojects, 'Include(Id, Name,Owner)'); projectContext.executeQueryAsync(dowithProjects, errorHandler); function dowithProjects() { var Projenumerator = Allprojects.getEnumerator(); while (Projenumerator.moveNext()) { var projectInfo = Projenumerator.get_current(); alert(projectInfo.get_title()); alert(projectInfo.get_id()); alert(projectInfo.get_owner().get_title()); } } } function errorHandler(sender, args) { if (args instanceof SP.ClientRequestFailedEventArgs) { alert(args.get_errorTraceCorrelationId()); alert( args.get_message()); alert(args.get_errorDetails()); } } </script>
The above code will return you the Project Name, Project ID, and Project Owner Name.
Thanks for reading.
Recent Comments