The CreatorCon Call for Content is officially open! Get started here.

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

Aman Kumar S
Kilo Patron

setValue doesnt work this way,

Try using:

dependencyGR.setValue("impact_analysis",current.impact_analysis); 

Best Regards
Aman Kumar

Thank you. Not working either. 

Harish KM
Kilo Patron
Kilo Patron

print log here gs.info("Impact analysis value".+ current.getValue('impact_analysis'));//check whether value is printing?

dependencyGR.impact_analysis.setDisplayValue('impact_analysis');

 

Regards
Harish

Kartik Sethi
Tera Guru

Hi @Daksha 

 

As you have already mentioned that imapct_analysis in Table 1 is of type reference and current.impact_analysis also belong to the same table (Table 1) which should also be of type reference. If that is the case then you need not use:

dependencyGR.impact_analysis.setDisplayValue( current.impact_analysis); 

instead, you can go for:

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

 


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