- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 05:56 AM
Hi all,
I have had a rather difficult request from a client and I'll do my best to explain what that is, but I'm essentially unsure as to how to approach a suitable method to implement it.
To start off, on our sys_user table we have a field called u_partner_role that is populated with a series of roles split using a semi-colon ';'.
On the ServiceNow Portal, we have a catalog item where you can only select users where this Partner Role field is populated with data.
What I want to be able to do is take this fields data, using the ; as a split populate these in a drop-down selection variable on the Catalog Item form.
So as you can see above, when the user is selected in the 'Partner' reference field, I want the data from that users u_partner_role field to be available in a drop down selection as below.
- Advising
- Principal
- DaaS
Any advice on this would be greatly appreciated even if it's just to direct me down the right path of what to look to include in a catalog client script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2023 08:29 AM
Thanks for details, there is minor issue with the for loop condition, corrected now.
for ( var i=0 ; valArray.length >i; i++){
g_form.addOption("practice_needed", valArray[i], valArray[i]);
}
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2023 06:45 AM
Can you share the field type of
practice_needed
Is should be select box type , share the screen shot of full page ( hide all client specific items )
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2023 07:05 AM
Everything else is default values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2023 08:29 AM
Thanks for details, there is minor issue with the for loop condition, corrected now.
for ( var i=0 ; valArray.length >i; i++){
g_form.addOption("practice_needed", valArray[i], valArray[i]);
}
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 05:53 AM
Thank you Ashish - this now works however I had to make some changes to the query I was trying to perform. My script is now as below.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var id ='';
id = newValue;
//alert('sys_id of user : ' + id);
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", id);
gr.query(myCallbackFunction); //Execute the query with callback function
//After the server returns the query recordset, continue here
function myCallbackFunction(gr){
while (gr.next()) { //While the recordset contains records, iterate through them
var keypart = gr.u_key_individual_of_partners;
var valArray = keypart.split('; '); // values will be in an array named valArray
for (var i=0 ; valArray.length >i; i++){
g_form.addOption('practice_needed', valArray[i], valArray[i]);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 06:25 AM
Thanks for marking accepted solution, happy to help.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution