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

amHow to fetch reference field data using widgets server script

Muru
Giga Expert

 

I am trying to create a custom widget which will take customer order number input and need to display account details of that customer order. I am struggling with fetching the customer account reference from customer order table. please is my code snippet 

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
var orders = new GlideRecord('sn_ind_tmt_orm_order');
  orders.addQuery('sys_id', '1ea9eea91b9f25104583ba63cc4bcb2e');
  orders.query();
 
// Instantiate the GlideRecord object for the customer_account table
var gr = new GlideRecord('customer_account');
 
// Add any necessary conditions to filter the records
//gr.addQuery('sys_id', 'd1ddfc501b5d2010f7c0dd33dd4bcb7e');
accountGR.addQuery('name','=',orders.getDisplayValue('account'));
 
// Execute the query
gr.query();
 
// Process the fetched records
if (gr.next()) {
  // Access the field values and assign them to variables
  var username = gr.getValue('name');
  var email = gr.getValue('email');
  var phone = gr.getValue('phone');
var address = gr.getValue('street') +','+ gr.getValue('city') +','+ gr.getValue('state') +','+ gr.getValue('zip');
var businessStructure = gr.getValue('business_structure');
var industry = gr.getValue('industry');
 
  // Pass the values to the widget's client script or HTML template for rendering
  data.username = username;
  data.email = email;
  data.phone = phone;
data.address = address;
data.businessStructure = businessStructure;
data.industry = industry;
}
 
})();
 
any idea why its not working ?

 

2 ACCEPTED SOLUTIONS

Muru
Giga Expert

Replaces order.customer_account with order.account 

its working now. Thanks a lot for your help 

 

View solution in original post

hi @Muru ,

Happy to hear that.

Please mark the response as helpful and correct answer

Regards

Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

6 REPLIES 6

Muru
Giga Expert

Replaces order.customer_account with order.account 

its working now. Thanks a lot for your help 

 

hi @Muru ,

Happy to hear that.

Please mark the response as helpful and correct answer

Regards

Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you