when a incident form assigned to email address is empty, we need to clear that & show error message

Srinivasu2
Tera Contributor

Hi Community,

 

Could you please share the code for this below scenario

 

when an incident form assigned to email address is empty, we need to clear that value & show error message

 

Thanks,

Srinivasu

3 REPLIES 3

Nishant8
Giga Sage

Hello @Srinivasu2, you can write a simple Business Rule against INC form like below. Please note that if you are unable to select AssignedTo.Email in 'When To Run' tab, click on show related fields and then you'll be able to dot walk to same field. let me know if this was something you were looking for?

Nishant8_0-1740830425853.pngNishant8_1-1740830457769.png

 

Singha8
Tera Expert

Hi @Srinivasu2 ,

 

we want real-time validation while filling out the form, we can use an onChange Client Script:

 

Client Script (onChange)

 

Table: Incident

 

Type: onChange

 

Field: assigned_to

 

Script:

 

 

(function executeRule(current, gForm, gSNC) {

    var assignedTo = gForm.getValue('assigned_to');

 

    if (!assignedTo) {

        gForm.clearValue('assigned_to'); // Clears the field

        gForm.showErrorBox('assigned_to', 'Assigned email address cannot be empty.');

    }

})(current, gForm, gSNC);

 

This will ensure that the error is displayed immediately when the user clears or l

eaves the field empty.

 

If you found this helpful, please mark it as Helpful so others can benefit too!

Thank you,

Ananya.

Debasis Pati
Tera Guru

Hello @Srinivasu2 ,

DebasisPati_0-1740836231265.png


You need to create one before business rule and put the above conditions along with use the below script in the advanced tab.

(function executeRule(current, previous /*null when async*/) {
// Check if the email address field is empty
if (!current.email_address) {
// Clear the email address field
current.email_address = '';
// Add an error message
gs.addErrorMessage('Email address cannot be empty.');
// Prevent the record from being saved
current.setAbortAction(true);
}
})(current, previous);

Please mark it as correct if this helps to resolve your issue.
This will encourage me to help more and learn more.

Regards,
Debasis