Pull data from cmdb table to variable on order form based on requested for

Petra Zelenak
Tera Contributor

I have an item where I want to pull information from a custom cmdb table based on the requested for field. It can be anyone not just the logged in user. So my attempts with Get User failed miserably.

 

Table: u_cmdb_ci_phone_number

Number is stored in the "name" field and is "assigned_to" to an employee who would be the same as "requested_for".

 

PetraZelenak_0-1666877654781.png

We also have an added filters on the Variable that the "Number State" has to be either Reserved or Assigned, and "Type" is Mobile.

This is a prerequisite check and call for later Order Guide options and I can't make it work to fill in this information. Can someone help me out? Thanks.

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

That's a good start, but based on your description, it sounds like this may be closer.

function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == "") {
         g_form.clearValue("phone_number_reserved");
    }

    var utilsLandlineAJAX = new GlideAjax("INV_ITSM_MobilePhoneCheckAjax");
    utilsLandlineAJAX.addParam("sysparm_name", "mobileDefaultPhoneNumber");
    utilsLandlineAJAX.addParam("sysparm_employee", newValue);
    utilsLandlineAJAX.getXMLAnswer(function(answer) {
        alert(answer)
        if (answer) {
            g_form.setValue("phone_number_reserved", answer);
        } else {
            g_form.clearValue("phone_number_reserved");
        }
    });
}

 

You can add alert lines in the Client Script, and gs.addInfoMessage lines in the Script Include temporarily to see how far the script is getting, the record retrieved by the GlideRecord, etc so you can see where it's going wrong.  On the Script Include, make sure the Client callable box is checked, then it sounds like the script should be more like this:

var INV_ITSM_MobilePhoneCheckAjax = Class.create();
INV_ITSM_MobilePhoneCheckAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    mobileDefaultPhoneNumber: function() {
        var answer = '';        
        var usr = this.getParameter("sysparm_employee");
        gs.addInfoMessage('usr = ' + usr)
        var gr = new GlideRecord('u_cmdb_ci_phone_number');
        gr.addQuery('assigned_to', usr);
        gr.addQuery('number_state', 'IN', 'reserved, assigned');
        gr.addQuery('type', 'mobile');
        gr.query();
        if (gr.next()) {
            gs.addInfoMessage('record found ' + gr.name)
            answer = gr.name;
        }
        return answer;
    },
    type: 'INV_ITSM_MobilePhoneCheckAjax'
});

 - depending on your field names and values in your custom table...

 

View solution in original post

5 REPLIES 5

You are welcome!