Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

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

 

Hi Danish,

 

It still isn't working with the above code

Hritik_0-1707133832144.png

 

Hritik_1-1707133857358.png

 

 

Hi @Hritik ,

 

Please remove the single quotes from line 7 & then try. current.variables... should not be in single qoutes.

 

Thanks,

Danish