The CreatorCon Call for Content is officially open! Get started here.

Displaying "Last logged into" or "Primary" customer/caller machine name on incident form.

jared_wentzel
Kilo Contributor

I am looking to create a field on the incident form that will auto populate,
after the customer is pulled up, with that customers primary CI or preferably
their most recently logged into CI (Machine Name) to make it easier for the
helpdesk to provide remote assistance. Basically I am asking, what is the most
accurate way of displaying the machine name that the person calling is on, at
the at the time of the call, on the incident form and how would I go about
implementing that. Has anyone attempted this? Any thoughts or suggestions?

On the "Last logged into CI" side of things...

We are looking to maybe implement the SCCM pluggin (Microsoft
SMS/SCCM Integration 2.0 - ServiceNow Wiki
) and have SCCM query the last
logged into machine name for the given customer. Even if we get that setup I
still don't know how I would have a field populate with that information with
the triggering event being the customer selection. But that is at a standstill
for the moment.

In the mean time I am trying to create a field that will auto populate when
the customer is selected with that persons assigned machine. So it would search
for all CI's assigned to that user where the class is equal to "computer". And I guess if
that customer is assigned multiple computers then the ServiceNow user would
just have to ask the customer which one they are calling about and then select
it.

It doesn't seem hard conceptually based on other systems I've worked with
but I'm not sure how to accomplish this with ServiceNow.

1 ACCEPTED SOLUTION

Use whatever makes sense in your instance.



For us our 'Incident For' field is 'caller_id' (Screenshot: caller_id).



I may have been tired yesterday because I notice that I didn't use g_form.setValue() to actually set the value on the form!


Try this instead:



function onChange(control, oldValue, newValue) {


  var caller = g_form.getValue('caller_id');//get the value of the caller/Incident For person


  g_form.setValue('u_default_ci', getMachine(caller));//set the variable: 'u_default_ci' on the form to


                                                                                                          //the return value of the getMachine function.


 


  function getMachine(c) {


      var gr = new GlideRecord('cmdb_ci_computer');//going out to the computer table


              gr.addQuery('assigned_to', c)//where cmdb_ci.compter.assigned_to is our caller from above.


              gr.query();


              if(gr.next()) {//if the record is found


                  return gr.name;//return the computer name of the caller


              }              


  }




I hope this one makes more sense!



When I return 'gr.name', I am actually returning the asset name from cmdb_ci_computer:


find_real_file.png


View solution in original post

10 REPLIES 10

justin_drysdale
Mega Guru

First you would have to add the new field to the Incident form.   I'd probably make it a variable of type: string.


Let's say you called the new field, 'u_newest_incident_field' which would be a very bad name to pick.



Next you can create a new onChange client script pointed at the caller_id field.


I'm guessing the caller_id field probably already has an onChange script attached, so you can append to that one if that is the case.



The script would look similar to this:


function onChange(control, oldValue, newValue) {



  var caller = g_form.getValue('caller_id');


  var u_newest_incident_field = getMachine(caller);


 


  function getMachine(c) {


      var gr = new GlideRecord('cmdb_ci_computer');//going out to the cmdb computer table


              gr.addQuery('assigned_to', c);//where the assigned_to field on cmdb computer is the caller_id on incident


              gr.query();


              if(gr.next()) {//if record found


                    //returning 1st result back to field:


                  return gr.assigned_to;


              }


  }



}


Alright I got the code added as a client script without pulling any error at least but when populating the field it does not autopopulate the field I created "u_default_ci" Below is the code I am using. I didn't see the caller_id field to point it to but I did see "Customer" so I tried that with no luck. I then tried "Priority" just for testing to see if I populated the customer and then changes the priority field if that would trigger it.. still no luck. Any suggestions??



This seems like it should be an easy thing to do but it is quite frusterating...


CS_DefaultCI.JPG


Use whatever makes sense in your instance.



For us our 'Incident For' field is 'caller_id' (Screenshot: caller_id).



I may have been tired yesterday because I notice that I didn't use g_form.setValue() to actually set the value on the form!


Try this instead:



function onChange(control, oldValue, newValue) {


  var caller = g_form.getValue('caller_id');//get the value of the caller/Incident For person


  g_form.setValue('u_default_ci', getMachine(caller));//set the variable: 'u_default_ci' on the form to


                                                                                                          //the return value of the getMachine function.


 


  function getMachine(c) {


      var gr = new GlideRecord('cmdb_ci_computer');//going out to the computer table


              gr.addQuery('assigned_to', c)//where cmdb_ci.compter.assigned_to is our caller from above.


              gr.query();


              if(gr.next()) {//if the record is found


                  return gr.name;//return the computer name of the caller


              }              


  }




I hope this one makes more sense!



When I return 'gr.name', I am actually returning the asset name from cmdb_ci_computer:


find_real_file.png


It works! only this is (and I wish I knew more about JavaScript) it populates when the form loads even if there is no customer selected. It grabs the first cmdb item availible. So I need to add an if statement around the gr.next somehow.