'requested_for' field on catalog task not working for client script.

DevtoSME
Giga Guru

I'm having issues with the 'request_for' field on the catalog task form not working in my client script.

this client script has been used on the incident/RITM/change and interction form.

 i tied to use 'sc_task.request_item.requested_for' and its still not working.

 

can anyone guide me on how to get this to work. 

I've attached screen shots

1 ACCEPTED SOLUTION

No worries, let's try this.

Create a Display Business Rule with the following script:

(function executeRule(current, previous /*null when async*/) {

	//Use one of the following 2 options:
	g_scratchpad.grade_of_service = current.request_item.requested_for.u_grade_of_service;

	//OR if you want to invoke your script include, you can do the following
	g_scratchpad.grade_of_service = new UserUtils().getGradesOfService(current.request_item.requested_for.toString());

})(current, previous);

Note that you can use either line of script.

 

Then within your client script:

//Replace the original script from line 7 to 17 with the following
if (g_scratchpad.grade_of_service == 'elite') {
    g_form.showFieldMsg('request_item.requested_for', 'This user is Elite', 'error');
} else {
    g_form.hideFieldMsg('request_item.requested_for');
}

View solution in original post

6 REPLIES 6

James Chun
Kilo Patron

Hi @DevtoSME,

 

A few things to note:

  • From the [sc_task] table, you are dot-walking to the [sc_req_item] record and then fetching the requested_for.  That means you will need to use g_form.getReference('request_item.requested_for')......
  • Using getReference is not a preferred way of fetching data, as it results in a transfer of unnecessary data. Instead, you can either use g_scratchpad or AJAX to fetch the data from the server in a more efficient manner - https://docs.servicenow.com/bundle/washingtondc-application-development/page/script/client-scripts/c...

Cheers

Ok i used g_scratcpad and im stll not getting a field message. this client script worked for the other tables so i want to know if the field name that im using is the issue. 

i tried using 'request_item.requested_for and 'sc_task.request_item.requested_for not working. 

Do you know if that is the issue?

Can you share what you have done for the g_scratchpad? (BR and Client Script)

 

In regards to the request_item.requested_for, I tried the following, and works fine. If you can share the script as well, I can have a look.

g_form.getReference('request_item.requested_for', function (userGr){
alert(userGr.name);
})

 

I didn't use a BR i kept the script include that i used for the other client script Please let me know if this is sufficient. i am learning on the job so I'm not as JavaScript savvy.