When form loads manager details needs to be populate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 09:03 AM
HI Community,
I have a requirement, need to populate the manager details in Is manager (list collector) field when the form is loaded.
In the catalog form there is variable set field named Requested for in that field when user opens the form in portal there name will be appear in the form....now i want to populate the manager of that user in Is manager field.
Help me with the onload client script as this needs to be display only for one particular catalog.
Thanks in Advance
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 09:43 AM
Hi @suuriya
You can use the following code
In client script
function onLoad() {
var requestedFor = g_form.getValue('opened_by');//change the field
var ga = new GlideAjax('GetManagerDetailsScript');
ga.addParam('sysparm_name', 'getManagerDetails');
ga.addParam('sysparm_requested_for', requestedFor);
ga.getXMLAnswer(callback)
function callback(response){
var answer=response;
alert(answer);
g_form.setValue('accessories', answer); //change the field
}
}
and in script include
var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerDetails: function() {
var requestedFor = this.getParameter('sysparm_requested_for');
var gr= new GlideRecord('sys_user');
gr.addQuery('sys_id',requestedFor);
gr.query();
if(gr.next()){
return gr.manager.getDisplayValue();
}
},
});
it is working in my PDI
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 10:30 AM
HI @SAI VENKATESH ,
Thanks for the reply
Above script is working as expected in portal but in native when i click on try button in catalog item and chceked it is not working value is not populating in list collector field but alert is returning the correct value.
Is there any specific reason for that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 10:39 AM - edited 05-09-2024 10:43 AM
Hi @suuriya
Uncheck the box
Applies on Requested Item as it is not required to run script on RITM form and make Isolate script to false
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 11:37 AM
HI @suuriya
in the variable attribute of the variable List collector add the following " glide_list". and it is working for me in my PDI in native view too.
Thanks and Regards
Sai Venkatesh