AutoFill field

Shir Sharvit
Tera Contributor

Hi,

In the incident form,
if the "service" field is empty, should be filled in automatically when the "service offer" field is filled. If the "service" field is full - do not update it.
The value to be filled in the "service" field is the value in the "service offer" parent field (which is a reference to the record).
The record that is filled has a field called "parent" - this is the value that will enter the "service" field.

 

Thank,Shir

9 REPLIES 9

Could you please write me the script?

(function executeRule(current, previous /*null when async*/) {
    if (current.service.nil() && !current.service_offer.nil()) {
        var parentRecord = new GlideRecord('parent_table'); 
        if (parentRecord.get(current.service_offer.parent)) {
            current.service = parentRecord.getValue('parent_field'); 
        }
    }
})(current, previous);

Try this one!

I need a solution with client script
The change should be made when filling out the form before saving

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Shir Sharvit ,
I trust you are doing great.
Please find the below script

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

    // Check if the 'service' field is empty
    if (!current.service.nil()) {
        return; // Exit if 'service' is not empty
    }

    // Check if 'service offer' is filled
    if (current.service_offer.nil()) {
        return; // Exit if 'service offer' is empty
    }

    // Get the 'parent' field value from the 'service offer' record
    var serviceOfferGr = new GlideRecord('service_offer_table'); // Replace 'service_offer_table' with the actual table name
    if (serviceOfferGr.get(current.service_offer)) {
        var parentValue = serviceOfferGr.parent.getValue();

        // Update the 'service' field with the 'parent' field value
        current.service.setValue(parentValue);
        current.update();
    }

})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



I need a solution with client script
The change should be made when filling out the form before saving