The CreatorCon Call for Content is officially open! Get started here.

Split data from a sys_user field and display as a selectable list on the Service Portal

Liam Rhodes
Kilo Guru

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 ';'.

LiamRhodes_0-1700142540997.png

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.

LiamRhodes_1-1700142793161.png

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.

 

1 ACCEPTED SOLUTION

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

View solution in original post

9 REPLIES 9

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

LiamRhodes_0-1700233507055.pngLiamRhodes_1-1700233530063.png

Everything else is default values.

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

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]);  
        }        
}

	}

}

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