Best way to create a field that combines static values with a variable within the record?

jlaue
Kilo Sage

Hi All -

I am looking for the best way to create/populate a custom field on the User form that I will name MGR Email, and it would do the following:

- prefix with a static value of:     mgr

- then grab the value in the Location field for that user (Location on sys_user)

- then suffix it with the email domain:   @xyz.com

So if I had a user record open and that user's location value was 123, then this MGR Email field would be populated for that user as:   mgr123@xyz.com    

If the user's location was empty - then it should result in no value populated within this MGR Email field for that user.

Thank you!!

1 ACCEPTED SOLUTION

Did you try this ?



This should be a before business rule with insert and update check boxes checked. Below is the script.


if (current.location!='')


        current.your_mgr_email_field = 'mgr'+current.location.name+'@xyz.com';


else


        current.your_mgr_email_field = '';



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

11 REPLIES 11

Hello - Thank you for this.   I have tried it out and I can't get it to populate the data into the field.   This is what I have:



String field on user form:


FName.JPG



Client Script:



CScript.JPG



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


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


          return;


    }



var ga = new GlideAjax('getUserLocEmailID');


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


ga.addParam('sysparm_caller', newValue);


ga.getXML(AsyncCall);


}



function AsyncCall(response) {


var answer = response.responseXML.documentElement.getAttribute("answer");


if(answer != ''){


var msgemail = 'mgr' + answer + '@XXXXXX.com';


g_form.setValue('u_mgr_email', msgemail);



}



else



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


 


}







Script Include:



SIncludde.JPG



var getUserLocEmailID = Class.create();


getUserLocEmailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {


getdetails: function(){


var gr = new GlideRecord('sys_user');


if(gr.get(this.getParameter('sysparm_caller')))


{


if(gr.getValue('location') != '')


return gr.getDisplayValue('location');


}


},


type: 'getUserLocEmailID'


});





Thank you!


Please have the onChange() client script on user's field for which you want to populate the data as per the user's location instead of MGR Email ?


Hello - apologies for the delayed reply.   I don't quite understand what you are referring to.   I would like for this new MGR Email field to always be populated in the User record, as long as the user location field is not empty.   I will be using this field to generate email notifications.   So for all the existing users and then all the users that are populated each day, this field should just be automatically populated if the user has a location.



Thank you!


Did you try this ?



This should be a before business rule with insert and update check boxes checked. Below is the script.


if (current.location!='')


        current.your_mgr_email_field = 'mgr'+current.location.name+'@xyz.com';


else


        current.your_mgr_email_field = '';



Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv -



Thanks for your response.   The business rule is not working for me.   Please see screenshots:



BRMGREmail1.JPGBRMGREmail2.JPG


(function executeRule(current, previous /*null when async*/) {



if (current.location !='')



        current.u_mgr_email = 'mgr'+current.location.name+'@abcsupply.com';



else



        current.u_mgr_email = 'blank';



})(current, previous);




BRMGREmail3.JPG



BRMGREmail4.JPG