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

No Luck. Still empty. 

Hi @Daksha 

 

Please provide more details on:

  • Business Rule is on which Table (you can use Table 1, Table 2, etc.) - so we can understand from where we are fetching current.impact_analysis
  • Type of current.impact_analysis
  • dependencyGR is on same table where current.impact_analysis is stored

Thanks

Business Rule is on the same table - table 1. 

  • Type of current.impact_analysis - reference
  • dependencyGR is on same table where current.impact_analysis is stored - Yes

Hi @Daksha 

Thanks for prompt reply. Please try the below-provided code:

//Sometimes in while Loop reference are referenced by addresses so we need to explicitly convert them to values by + '' or .toString()
dependencyGR.setValue( 'impact_analysis',current.impact_analysis + ''); 

Try the above changes and let me know if this works for you.


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Thanks for the information Karthi Sethi. 

Not data still.