Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Fix script.

Thalavai m
Tera Contributor

Hi all,

I want to copy records from a field in child table to a field in parent table I have tried fix script for this but its not copied can you please help me to do this. and this is the script I have tried 

(function executeRule(current) {

   var parentTable = 'cmdb_ci_service_auto';

   var childTable = 'cmdb_ci_service_discovered';

   

   var parentRecord = new GlideRecord(parentTable);

   if (parentRecord.get(current.parent)) {

       var childRecord = new GlideRecord(childTable);

       if (childRecord.get(current.child)) {

           parentRecord.u_ug_it_service_owner = childRecord.u_it_service_owner;

           parentRecord.update();

       }

   }

})(current);

7 REPLIES 7

I tried your script but its showing 

Thalavaim_1-1712757285609.png

 

 

HI @Maddysunil 

Try this logic .. i have tested in my PDI

var parentTable = 'incident';
    var childTable = 'incident';

    var childRecord = new GlideRecord(childTable);
    if (childRecord.get('968dd5a893650210938374dcebba10ab')) {
        gs.info('Child record found: ' + childRecord.getDisplayValue());
        
        var parentRecord = new GlideRecord(parentTable);
        if (parentRecord.get(childRecord.parent_incident)) {
            gs.info('Parent record found: ' + parentRecord.getDisplayValue());
            
            parentRecord.contact_type = childRecord.contact_type;
            parentRecord.update();
            
            gs.info('Field value copied successfully.');
        } else {
            gs.info('Parent record not found for sys_id');
        }
    } else {
        gs.info('Child record not found for sys_id');
    }

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna

My Results 

Parent Incident : INC0000044Parent Incident : INC0000044Child Has Channel : PhoneChild Has Channel : PhoneTested Code LogicTested Code LogicParent Channel has Updated to PhoneParent Channel has Updated to Phone