Stockroom attribute should be reflected based on the task assignee's part of stockrooms

daas
Tera Contributor

Hi All,

 

we have a field "stockroom" in catalog task which is reference of alm_stockroom table. This stockroom field should have the list of names related to location of assigned_to user in the task 

 

example record of alm_stockroom table as below

NameAssignment groupExternallocationmanagerDomain
IN-Bangalore-StockroomSOFTWARE-BANGALOREFALSEIN-BangaloreAnujglobal

 

I am able to get the list of stockroom names from alm_stockroom based on location of respective assignee. But I am not able to populate the list of records in the reference field in task

 

Here is the script include:

 

 

 

var TESTTEST = Class.create();
TESTTEST.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserInfo: function() {
        var stockroomArr = [];
        var UserID = this.getParameter("sysparm_uname");
 
        var result = this.newItem("result");
        var users = new GlideRecord("sys_user");
        //users.get(UserID);
        users.get('sys_id', UserID);
        users.query();
        if (users.next()) {
            var location = users.location.name.toString();
            gs.log("location sysid is" + location);
            var gr1 = new GlideRecord('alm_stockroom');
            gr1.addQuery('location.name', location);
            //gr1.addQuery('u_active','true');
            gr1.query();
            while (gr1.next()) {
                gs.log("stockrooms names are " + gr1.name.toString());
                var name = gr1.name.toString();
               // var list1 = gr1.sys_id;
                stockroomArr.push(name);
                gs.log("assigned to stockrooms are 26" + stockroomArr);             
            }
            return " "+stockroomArr;
            gs.log("chaithraaaa111" + stockroomArr);
        }
    },
    type: 'TESTTEST'
});

 

 

 

Onchange of assigned to filed Global client script 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var taskid = g_form.getValue('u_task_id');
    alert("taskid6" + taskid);
    if (taskid == 'WFLeaver005') {
        if (newValue != '') {
            alert("assigned to is" + newValue);
 
            var ga = new GlideAjax('TESTTEST');
            ga.addParam('sysparm_name', 'getUserInfo');
            ga.addParam('sysparm_uname', newValue);
            ga.getXML(myCallBack);
        }
    }
 
    g_form.clearValue("stock_room");
 
    function myCallBack(response) {
       // var splitAnswer = [];
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var splitAnswer = answer.split(",");
        alert("line :" + splitAnswer.length + splitAnswer);
        for (var i = 0; i < splitAnswer.length; i++) {
            alert("chaithraaa 28" + splitAnswer[i]);
            g_form.setValue('stock_room', splitAnswer[i]);
        }
    }
}

 

 

 

Can you please help me to get the solution.

 

Thanks,

Daas

0 REPLIES 0