Get Custom Field Value using JavaScript Object Model(JSOM)

Get Custom Field Value using JavaScript Object Model(JSOM)

In this article, I will describe to Get Custom Field Value using JavaScript Object Model(JSOM).The custom field value can be read by different- different ways as I discussed in my previous post.

Read Custom Field Value Using CSOM in Project Online

Read Lookup Type as well Without lookup Custom Field using PSI

<script src="../_layouts/15/jquery-1.9.1.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;
    var Allprojects;
    var customField_Data = [];

    $(document).ready(function () {
        SP.SOD.executeOrDelayUntilScriptLoaded(ReadCustomFields, "PS.js");
    });
    function ReadCustomFields() {

        var projectContext = PS.ProjectContext.get_current();
        var Allprojects = projectContext.get_projects();
        projectContext.load(Allprojects, 'Include(Id, Name, CustomFields, IncludeCustomFields, FieldValues)');
        projectContext.executeQueryAsync(dowithProjects, errorHandler);
        function dowithProjects() {
            var Projenumerator = Allprojects.getEnumerator();
            while (Projenumerator.moveNext()) {
                var projectInfo = Projenumerator.get_current();
                doWithProject(projectInfo);
            }
        }
    }
    function doWithProject(projectInfo) {
           
        alert('Project Id:   ' + projectInfo.get_id());
        alert('Project Name: ' + projectInfo.get_name());
        var fieldValues = projectInfo.get_includeCustomFields().get_fieldValues();
        var CFenumerator = projectInfo.get_customFields().getEnumerator();
            while (CFenumerator.moveNext()) {
                var customField = CFenumerator.get_current();
                alert(customField.get_name() + " = " + fieldValues[customField.get_internalName()]);
                
            }
        }
        function errorHandler(sender, args) {
            if (args instanceof SP.ClientRequestFailedEventArgs) {
                alert(args.get_errorTraceCorrelationId());
                alert( args.get_message());
                alert(args.get_errorDetails());
            }
            
        }
       
    </script>

 

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!