Suitescript 2.0: Setting Internal ID from a field

When a case comes in from a customer – the account no is supplied. I need to do a lookup to get the internal id of that account no so I can set the company field on a case record. Right now the objRecord is getting set using the account no – but how can I override this if I have an internal ID?

varcase_data=restletData[data];
for (varkeyincase_data) {
if (key=='company') {
log.debug("Account No: "+case_data[key]);
varcompany_id=case_data[key];
varaccount_no=getAccountNo(company_id);//TODO: lookup account no to get customer internal id
log.debug(account_no)
}
if (case_data.hasOwnProperty(key)) {
objRecord.setValue({
fieldId:key,
value:case_data[key]
});
}
}


                
Rookie Asked on October 1, 2019 in SuiteScript.

Its not very clear what you want, primarily because I don’t know what you mean by account no. My guess is that the value in your company key is being used to lookup the internal id of the company you want to set in the company field on the support case. In which case you would use:

 objRecord.setValue({
  fieldId: "company",
  value: account_no
});

on October 1, 2019.

Sorry, let me try to explain. I am creating a RESTLet which is to create a case from a website. As you know the case requires a company. When customer records are created we send the customers a portion of the Customer ID. Ex: in NS we may have 10001 Test Company, but the customer is sent 10001 as their ‘account no’.

Now, when the customer submits the online form we ask for their ‘account no’. For me to set the company field on a case record I need the account no to do a lookup in a saved search and get the customer’s internal ID, which is what I need to set the company field. For now, I am just hard coding the internal ID for test purpose.


{"data":[{"customform":"121","company":"10001","title":"AAA Postman Test 6","incomingmessage":"Sending From Postman 1"}]}

Let’s assume the above is sent to the RESTLet. I don’t want to set the company value to 10001, instead I do a lookup and get the corresponding internal ID – say 106750. But I get an error as it is setting 10001.

on October 1, 2019.
Add Comment
2 Answer(s)
Best answer

Either use an if/else statement to make your code do different things for different conditions. Or make is so that your two conditions act the same; in this case that involves changing your data object’s account number to be an internal id.

var case_data = restletData[data];
for (var key in case_data) {
  if (key == "company") {
    log.debug("Account No: " + case_data[key]);
    var company_id = case_data[key];
    var account_no = getAccountNo(company_id); //TODO: lookup account no to get customer internal id
    log.debug(account_no);
    case_data[key] = account_no;
  }
  if (case_data.hasOwnProperty(key)) {
    objRecord.setValue({
      fieldId: key,
      value: case_data[key]
    });
  }
}
Intermediate Answered on October 2, 2019.

That worked – thanks.

on October 2, 2019.
Add Comment

Make a search to get all the Accounts and on the left side of the search you will have Account ID for a particular Account.

Beginner Answered on October 1, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor