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

Need to get requested_for.location.country in catalog script

conanlloyd
Giga Guru

I have been given a new requirement for our iphone request catalog item to try and prevent US users erroneously selecting Vodafone as a provider.   I set up an onChange script for my vendor variable but am running up against the fact that you can't dot-walk in client scripts.   Please help as I have never done any glide ajax work

Here are the conditions:

  1. The requested for person is located in the united states (requested_for.location.country == 'USA')
  2. The vendor selected is Vodafone (newValue =='Vodafone')

If both conditions are true, then pop up a confirmation window where they can confirm or cancel.   If I don't worry about condition 1 the below script works great.   However, I need that condition too.

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

          return;

    }

    //Type appropriate comment here, and begin script below

  if (newValue == 'Vodafone') {

  var con = prompt("Vodafone is normally reserved as a provider for non US-Based employees. \n\nType 'Confirm' and click 'OK' if you are sure want to use this provider.   \n\nOtherwise click 'Cancel'");

  if (con == null || con == "") {

  g_form.setValue('phone_mc_provider','');

  }

  if(con == 'Confirm'){

  g_form.setValue('Special_Requirements', 'Vodafone confirmed as the correct provider by request submitter.');

  gsftSubmit(gel('sysverb_update_and_stay'));

  //gsftSubmit(gel('sysverb_update'));

  }

  }

}

Thanks in advance for any help!

1 ACCEPTED SOLUTION

Justin Abbott
Giga Guru

Here's an example of how you could achieve that, Conan.



Client script:



function onChange(control, oldValue, newValue, isLoading) {


if (isLoading || newValue == '') {


return;


}



var ga = new GlideAjax('MyUserAjax');


ga.addParam('sysparm_name', 'getUserCountry');


ga.addParam('sysparm_id', g_form.getValue('requested_for'));


ga.getXML(ajaxResponse);



function ajaxResponse(response) {


var country = response.responseXML.documentElement.getAttribute('answer');



if (newValue == 'Vodafone' && country == 'USA') {


var con = prompt("Vodafone is normally reserved as a provider for non US-Based employees. \n\nType 'Confirm' and click 'OK' if you are sure want to use this provider.   \n\nOtherwise click 'Cancel'");


if (con == null || con == "") {


g_form.setValue('phone_mc_provider','');


}


if(con == 'Confirm'){


g_form.setValue('Special_Requirements', 'Vodafone confirmed as the correct provider by request submitter.');


gsftSubmit(gel('sysverb_update_and_stay'));


//gsftSubmit(gel('sysverb_update'));


}


}


}


}



Script Include with 'Client callable' field checked:



var MyUserAjax = Class.create();


MyUserAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {



getUserCountry: function() {


var userId = this.getParameter('sysparm_id');


var result = this.newItem('result');



var gr = new GlideRecord('sys_user');


gr.get(userId);



return gr.location.country;


},




      type: 'MyUserAjax'


});


View solution in original post

5 REPLIES 5

Glad to help!