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

AshishKM
Kilo Patron
Kilo Patron

Hi @AysenurU , 

Have you written this code in onChange Client Script or some Business Rule. 

I see, you have used the current object, means its business rule. If that is the case, you can set this value without any script code. 

 

First you decide, are you looking for client side change or server side ( means on/after save ).

For client side , write client script on incident table for caller column.

For server side, update the BR with below.

 

This is BR [ insert ] on Incident table with condition check for caller.

AshishKM_0-1717070306735.png

Use Action tab for setting channel value

AshishKM_1-1717070391682.png

 

 

-Thanks,

AshishKM

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hey Ashish

 

First I tried to create a Business role without any scripts. 

AysenurU_0-1717072175042.png

AysenurU_1-1717072199731.png

But it is not changing or updating anything on my Incident form😔

 

Then I wanted to try Client script.

AysenurU_3-1717072601307.png

However, it did not work either. 

AysenurU_2-1717072525542.png

 

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