When form loads manager details needs to be populate

suuriya
Tera Contributor

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

5 REPLIES 5

SAI VENKATESH
Tera Sage
Tera Sage

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

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.

suuriya_1-1715275773545.png

 

 

 

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

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.

 

cn21.PNG

 

Thanks and Regards

Sai Venkatesh