How to get in a variable the request number and use it in a script

jorgetop
Kilo Contributor

Hi there,

I ´m trying to get the request number generated and use it in a onLoad script, and if the request number ends with pair number,

a field called "Service Provider(single text)" that I've created will be auto populated with a string value(Name of the provider) or if the condition

is false(request number ends with odd number) the field "Service provider" will be auto-populated with another provider name.

This functionality is because the user needs that the service provider appears in the report, and there are two providers, hence the request ending

with odd number triggers the emails to one provider and the ones ending with a pair number go to the other provider.

Thanks in advance, appreciate any help.

1 ACCEPTED SOLUTION

Hi Jorge,



Please add a run script block like below in Workflow


find_real_file.png



Inside Run script block use the below script:



var reqNum = current.request.number;


var array = reqNum.toLowerCase().split('');


arrLength = array.length;


var str = reqNum.substr(array.length-1, array.length);


                      if (str=='0'||str=='2'||str == '4'||str == '6'||str == '8'){  


current.variables.provider = 'Movil Ride';


                      }  


else current.variables.provider = 'Movil Ex';




Thanks,


Arindam


View solution in original post

6 REPLIES 6

Arindam Ghosh
Mega Guru

Hi Jorge,



You can use like below script in your onLoad Client Script modify the field and service provider names properly:



function onLoad() {


reqNum = g_form.getReference('request').number;


var array = reqNum.toLowerCase().split('');


arrLength = array.length;


var str = reqNum.substr(array.length-1, array.length);


                      if (str=='0'||str=='2'||str == '4'||str == '6'||str == '8'){  


g_form.setValue('u_service_provider', 'ServiceProvider1');


                      }  


else g_form.setValue('u_service_provider', 'ServiceProvider2');


}  


   



Thanks,


Arindam


Hi Arindam,



Thanks for your help, I've tried the script you provided me, but still not auto populating the field, it ´s remains blank.


find_real_file.png


If you have another suggestion I'll appreciate



Regards!


Please share your script.


The variable provider is hidden in the form(single text), and it should be autopopulated depending the end of the request number



function onLoad(){


reqNum = g_form.getReference('request').number;


var array = reqNum.toLowerCase().split('');


arrLength = array.length;


var str = reqNum.substr(array.length-1, array.length);


      if (str=='0'||str=='2'||str == '4'||str == '6'||str == '8'){


g_form.setValue('provider', 'Movil Ride'); // provider is the variable that should get the string value 'Movil Ride'


                      }


else {


g_form.setValue('provider', 'Movil Ex');


}


}


Thanks