Need help with Populating manager field after Catalog form submission

Hritik
Tera Expert

Hi Community,

 

I am trying to populate the manager field on catalog form after form is submitted or let's say I am submitting request via REST API call but manager field should be populated when RITM is created. 

I can populate field OnLoad, OnChange but it's failing with the same code for OnSubmit.

 

I used two methods for Auto-population:

1. Auto-populate feature on a Variable

2. Script Include and Client script

 

Please find my code below:

 

Script Include:

// Script Include: ManagerLookup
var ManagerLookup = Class.create();
ManagerLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getManagerName: function () {
        var userId = this.getParameter('sysparm_user_id');
        var userGR = new GlideRecord('sys_user');
        if (userGR.get(userId)) {
            return userGR.manager;
        }
        return '';
    },
    type: 'ManagerLookup'
});

 

Client Script:

Hritik_0-1707121416585.png

function onSubmit() {
   //Type appropriate comment here, and begin script below
   
   var userId = g_form.getValue('variables.employee_to_offboard');

    // Call the Script Include using GlideAjax
    var ga = new GlideAjax('ManagerLookup');
    ga.addParam('sysparm_name', 'getManagerName');
    ga.addParam('sysparm_user_id', userId);
    ga.getXMLAnswer(function (answer) {
        
        g_form.setValue('variables.manager', answer);
  });
}

 

Please suggest what is it that i'm missing here?

I just need Manager field to be populated based on user selection on the catalog form but this also should be successful if I create request via Service Catalog API.

 

 

Thanks in Advance,

Hritik

1 ACCEPTED SOLUTION

Hi @Hritik ,

 

User info will be der on the form right. Then u need to tweak the code a bit. Something like this

 

var managerID = new GlideRecord('sys_user');
if(managerID.get('current.variables.user')){
current.variables.manager = managerID.manager;
current.setWorkflow(false);
current.update();
}

 

Thanks,

Danish

 

View solution in original post

7 REPLIES 7

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Hritik ,

 

You can try creating a After Insert BR only for this catalog Item (you can select it in the condition by dot walking). & in the BR u can just GlideRecord the Requested Item Table then populate the manager field using 

 

var gr = new GlideRecord('sc_req_item');
if(gr.get(current.sys_id)){
gr.variables.manager = '<sys id of manager>';
gr.update();
}

This will help u when u submit the form manually as well as via API call.

 

Thanks,

Danish

 

Hi @Danish Bhairag2 ,

 

Could you please share the code pls ?

Also, I'm still confused why does OnSubmit Client Script does not work for this ?

 

Thanks in Advance.

Hi @Hritik ,

 

I have shared the code in the my previous comment only. I have updated it. u can add that code in after insert business rule on RITM table with a condition as Requested item.item - your item name

 

Thanks,

Danish

 

Hi Danish,

 

sys_id of manager is dynamic entry. it will be different always when user is selected on the form.

How will it help to retrieve the sys_id of manager to be auto populated