Auto populating a field value depending on another field option in Incident form

AysenurU
Tera Contributor

Hello

I have a question regarding Business Rule Script. 

When the caller is Abraham Lincoln, I want Channel to be populated as Self-service. (As you can see in the image below)

AysenurU_1-1717069555571.png

 

 

Here is the script but it is not working. 

 

(function executeRule(current, previous /*null when async*/) {
    // Ensure the caller ID is present
    if (current.caller_id) {
        // Get the caller's record from the sys_user table
        var caller = new GlideRecord('sys_user');
        if (caller.get(current.caller_id)) {
            // Check if the caller's name is Abraham Lincoln
            if (caller.name == 'Abraham Lincoln') {
                // Set the channel to Self Service
                current.channel = 'self-service';
            }
        }
    }
})(current, previous);

 

I appreciate any help.

 

TIA 😃

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @AysenurU ,

 

You can write onChange client script and populate the Channel value,

swathisarang98_0-1717081311559.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

  var caller = g_form.getReference('caller_id', currentUser1);

}
function currentUser1(caller){
	if(caller.name == 'Abraham Lincoln'){
		
		g_form.setValue('contact_type','self-service');
	}
}

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

6 REPLIES 6

AysenurU
Tera Contributor

Hi @swathisarang98 

 

Thanks for your reply. I have just seen that you also answered my friend's very same question. Your solution works well. Thank you. 😊

@AysenurU  Thank you for this ! Please close this thread by accepting the appropriate answer