0

I am working with Office 365/SP Online. For one of the Requirements that I am working with, I have two functions both returning values.

Below is the code for first function, returning ctype.

function getContentTypeSelectionID(){
    var ctype = $("select[title='Content Type']").val();
    alert(ctype);
    return ctype;
}

Second Function is as shown below.As you can see I am returning variable ccid.

function getListContentTypes() {  
var clientContext = new SP.ClientContext.get_current();  
if (clientContext != undefined && clientContext != null) {  
var web = clientContext.get_web();  
this.listCollection = web.get_lists();  
this.list = listCollection.getByTitle("Finance");  // Provide the needed List or Document Library Name  
this.contentTypeCollection = list.get_contentTypes();  
clientContext.load(this.contentTypeCollection);  
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));  
}  
} 

function onQuerySucceeded() {  
//var contentType = 'Associated Content Types:\n '  
var contentTypeEnumerator = this.contentTypeCollection.getEnumerator();  

while (contentTypeEnumerator.moveNext()) {  
var content = contentTypeEnumerator.get_current();  
if(content.get_name()=="Project Financing"){  
var ccid = content.get_id();
return ccid;
//alert(ccid);               
//alert(content.get_id()); 


}  
//contentType += content.get_name() + '\n';  
}  
//alert(contentType);                                
}  
function onQueryFailed(sender, args) {  
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
}  

Both of the above functions return IDs and What I want to do is in a third function, I want to compare values returned by both the functions, how should I do that. Below is the code for third function. As you can see I am calling above two functions right before the If statements start so instead of doing contenttype="0x0101..." inside if, I want to replace that by comparing values returned by those two functions.

function ValidateForm(){
    //var ctype = $("select[title='Content Type']").val();

    var Iserror = true;

    RemoveAllStatus();
    str= "Please review following errors :";
    var profinval = $("select[title='Project Financing DocType']").val();
    var Progtype = $("select[title='Program Type']").val();
    var doctype = $("select[title='Document Type']").val();
    var contenttype = $("select[title='Content Type']").val();
    getContentTypeSelectionID();
    getListContentTypes();
    if(contenttype == "0x01010037DDB8B9B2CA3945B95DF13B1C5D88E800EC86D94776AD264D948AF095CCE33811" && profinval!= "Requisitions" && profinval!= "Government/Subsidy" && profinval!= "Capital Raise"){
        if(profinval.length < 1 && getListContentTypes() == contenttype && profinval!= "Requisitions" && profinval!= "Government/Subsidy" && profinval!= "Capital Raise") {
        $("select[title='Project Financing DocType']").attr("style", "border: solid 1px #ff4c42 !important");
        str+="</BR>Project Financing DocType field cannot be blank."
        Iserror = false;
    }


    if(Progtype.length < 1 && getListContentTypes() == contenttype && profinval!= "Requisitions" && profinval!= "Government/Subsidy" && profinval!= "Capital Raise"){
        $("select[title='Program Type']").attr("style", "border: solid 1px #ff4c42 !important");
            str+="</BR>Program Type field cannot be blank."
        Iserror = false;
    }


    if(doctype.length < 1 && getListContentTypes() == contenttype && profinval!= "Requisitions" && profinval!= "Government/Subsidy" && profinval!= "Capital Raise"){

        $("select[title='Document Type']").attr("style", "border: solid 1px #ff4c42 !important");
            str+="</BR>Document Type field cannot be blank."
        Iserror = false;
    }


    }
    if(!Iserror){NoPermMsg(str)};
    str = "";
    return Iserror;
}

Your Answer

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

Browse other questions tagged or ask your own question.