Autopopulate req for inside variable set variable

RoseD
Giga Contributor

I want to autopopulate logged in user in Requested for variable(Ref type). The variable contact is a part of variable set contact_and_account. For a perticular RP want to do this using client script. please help.

3 REPLIES 3

Kieran Anson
Kilo Patron

Using a client script would be less efficient then using the default value option on the variable set (see below).

 

KieranAnson_0-1716203725165.png

 

 

But for client script you'd do the following

function onLoad() {
   g_form.setValue('requested_for' , g_user.userID); //'requested_for' being the variable name
   
}

for default value it will apply for all... but i want to apply for a perticular Record producer........

RoseD
Giga Contributor

Script include:

var requestor_details = Class.create();

requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    requestor_info: function() {
        var result = this.newItem("result");
        var logged_user = gs.getUserID();
        var user_detail = new GlideRecord('sys_user');
        user_detail.addQuery('sys_id', logged_user);
        user_detail.query();
        while (user_detail.next()) {
            result.setAttribute("user", user_detail.sys_id);
            // result.setAttribute("phone", user_detail.phone);
            // result.setAttribute("email", user_detail.email);
            // result.setAttribute("location", user_detail.location);
        }
    },

    type: 'requestor_details'
});
RoseD_0-1716203756680.png

 

Client script:

function onLoad() {
    //Type appropriate comment here, and begin script below
    var ga = new GlideAjax("requestor_details");
    ga.addParam("sysparm_name", "requestor_info");
    ga.getXML(ajaxResponse);

    function ajaxResponse(serverResponse) {
        var result = serverResponse.responseXML.getElementsByTagName("result");
        var user = result[0].getAttribute("user");
        // var email = result[0].getAttribute("email");
        // var loc = result[0].getAttribute("location");
        g_form.setValue('contact', user);
    }
}
 
RoseD_1-1716203806048.png

 

 

Not working..........