How to call Request for field value into Service Portal service request form submission

BanuMahalakshmi
Tera Contributor

Hi,

In service Request form, we have variable - New service account name. After submission of this form, New service account name value should display Instead of, request for variable logic is picking up the submitted by user name. Please assist me to reflect new service account name into Request for. Thanks.

 

  • BanuMahalakshmi_0-1725630049490.png

     

3 REPLIES 3

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @BanuMahalakshmi 

 

Actually I didn't get you question properly.. What I understand is:

you have created a variable called New service account name on catalog form, after submission of catalog form the name should be populated at Requested for in RITM form.

 

if my understanding is correct, you have to crate New service account name variable with Requested For type (instead of reference type). This field type is only specified for catalog variables.

 

Hope I understand correctly, and this is the answer for my understanding....

if my understanding is wrong please elaborate your question.

 

Thank you

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Abhishek_Thakur
Mega Sage

Hello @BanuMahalakshmi ,

 

You need to use the script include and client script as requested_for field value comes from "sys_user" table.

 

You can use the below script include and client script.

Script Include:
var GetValue = Class.create();
GetEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    demoTest: function() {
        var user = this.getParameter("sysparm_requested_for");
		var gr = new GlideRecord('sys_user');
		gr.addQuery("sys_id",user);
		gr.query();
		if(gr.next()){
			return gr.name;
		}
    },
    type: 'GetEmail'

});

 

Client Script

Please use the onchange Catalog client script for requeusted_for field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   var ga = new GlideAjax('GetEmail');
   ga.addParam("sysparm_name","demoTest");
   alert("test");
   ga.addParam("sysparm_caller_id",g_form.getValue("requested_for"));
   alert("test1");
   ga.getXML(callback);
   function callback(response){
	alert('test');
	var answer = response.responseXML.documentElement.getAttribute("answer");
	alert("Name" +answer);  // Check to get the value.
   }

   //Type appropriate comment here, and begin script below
   
}

Please accept the answer and give thumbs up, if it helps you.

AnveshKumar M
Tera Sage
Tera Sage

Hello @BanuMahalakshmi 

From what I understood, the value that you have entered in "New Service Account Name" variable should become the requested for user. If this is what you want, please note the following points.

 

1. The Requested for field in RITM referes to sys_user table, so the user should be already present in the system. If your "New Service Account Name" variable is reference type to User table, just change the variable type to "Requested for" in your catalog.

2. If the New Service Account Name variable is of text type and there is no user account with that name at the time the request submission, you can not make it in to "Requested for" as the requested for should always point to an existing user account.

 

Plese mark my answer helpful 👍 and accept as a solution if it helped ✔️

Thanks,
Anvesh