- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 10:26 PM
Hi Team,
we are having a custom scripted get API and we have few hard code values as well, So we are using the property to fetch the values. But we have to fetch for array list and user record values ,Any suggestion please
hard_code_values :abc,xyz,test,test1,test2,Testing,Regular testing"
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
var values=[abc,xyz,test,test1,test2]
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.caller_id = "Testing";
grInc.contact_type = "Regular testing";
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 03:37 AM
Hi,
So are you sure the 1st 5 values from that property are to be checked for query parameters and next 2 are to be used for inserting?
if yes then update as this
Array will be running only for 1st 5 values
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
var emptyValue = []; // this array holds fields for which there isn't any value from query Params
for(var i=0;i<4;i++){
if(queryParams[arr[i]][0] == '' && queryParams[arr[i]][0] == undefined){
emptyValue.push(arr[i].toString());
}
}
// now you can determine if that array has any field or not
if(emptyValue.length > 0){
// means some field is empty so give error
}
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.short_description = queryParams.abc[0];
grInc.description = queryParams.xyz[0];
grInc.note = queryParams.test[0];
grInc.worknote = queryParams.test1[0];
grInc.subnote = queryParams.test2[0];
grInc.caller_id = arr[5]; // 6th value
grInc.contact_type = arr[6]; // 7th value
var ID = grInc.insert();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 03:37 AM
Hi,
So are you sure the 1st 5 values from that property are to be checked for query parameters and next 2 are to be used for inserting?
if yes then update as this
Array will be running only for 1st 5 values
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
var emptyValue = []; // this array holds fields for which there isn't any value from query Params
for(var i=0;i<4;i++){
if(queryParams[arr[i]][0] == '' && queryParams[arr[i]][0] == undefined){
emptyValue.push(arr[i].toString());
}
}
// now you can determine if that array has any field or not
if(emptyValue.length > 0){
// means some field is empty so give error
}
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.short_description = queryParams.abc[0];
grInc.description = queryParams.xyz[0];
grInc.note = queryParams.test[0];
grInc.worknote = queryParams.test1[0];
grInc.subnote = queryParams.test2[0];
grInc.caller_id = arr[5]; // 6th value
grInc.contact_type = arr[6]; // 7th value
var ID = grInc.insert();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:56 AM
This property not working How can i do fetch cmdb data