Gliderecord Insert is not working while inserting the reference field values.

Daksha1
Tera Contributor

Hi all,

I'm facing this strange issue while using gliderecord Insert()

Scenario:  I have requirement where when a record of type 'service' is inserted in table_1 , I have a business rule that inserts 1 or more records in the same table- Table_1 with type 'capability'.   The code is as follows [Here the impact_analysis is the reference field. ]  :

while(gr_rel.next()) {

    var dependencyGR = new GlideRecord('table_1');
    dependencyGR.initialize();
    dependencyGR.depends_on =  gr_rel.parent;  //working as expected
    dependencyGR.depends_on_table= 'cmdb_ci_business_capability'; //working as expected
    dependencyGR.impact_analysis.setDisplayValue( current.impact_analysis);  //Not working

      dependencyGR.insert();

//tried dependencyGR.impact_analysis= current.impact_analysis;  Not working.

//tried dependencyGR.impact_analysis= current.impact_analysis.sys_id;  Not working.

//tried  dependencyGR.setValue( 'impact_analysis',current.impact_analysis); 

// dependencyGR.insertWithReferences();  //gave error "insertWithReferences not in scope"     
}

I read that using Display value works for reference fields. Not working for us. The value in the New inserted record is BLANK. But I tested that current.impact_analysis has value , but it is not setting the value. 

Can anyone please suggest a method that works for this case. 

 

15 REPLIES 15

Jaspal Singh
Mega Patron
Mega Patron

dependencyGR.impact_analysis.setDisplayValue( current.impact_analysis);  //Not working

should work

You can also try

dependencyGR.impact_analysis=current.impact_analysis;  

Also, try making Business Rule run After insert once for a check.