Last active
July 7, 2023 14:56
-
-
Save BigRaj/f79be50ac93d53d4268d416128aedfdf to your computer and use it in GitHub Desktop.
Extends SP.CamlQuery to generate a CamlQuery for lookup values (MDS Compliant)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paramters: lookupFieldName - Internal name of field | |
// lookupFieldValue - ID of lookup item | |
SP.CamlQuery.createLookupQuery = function SP_CamlQuery$createLookupQuery(lookupFieldName,lookupFieldValue){ | |
this.lookupFieldName = lookupFieldName || null; | |
if(this.lookupFieldName === null){ | |
console.error('Missing Parameter(s): lookupFieldname and lookupFieldValue'); | |
return; | |
} | |
this.lookupFieldValue = lookupFieldValue || null; | |
if(this.lookupFieldValue === null){ | |
console.error('Missing Parameter: lookupFieldValue'); | |
return; | |
} | |
var $v_0 = new SP.CamlQuery(); | |
$v_0.$l_1 = '<View>\r\n <Query>\r\n <Where>\r\n <Eq>\r\n <FieldRef Name=\"' + this.lookupFieldName + '\" LookupId=\"TRUE\" />\r\n <Value Type=\"Lookup\">' + this.lookupFieldValue + '</Value>\r\n </Eq>\r\n </Where>\r\n </Query>\r\n</View>'; | |
return $v_0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment