Wednesday, January 23, 2019

Convert Customers to Lead or Prospect through SuiteScript

How to Convert Customers to Lead or Prospect through SuiteScript

Leads can be converted to Prospect once a transaction has been made or you manually change the Status. To do this in scripting, you will need to change the entitystatus value based on the Customer Stage where you want Customer records to be converted. You can look this up on Customer Status List page by navigating to Setup > Sales > Customer Statuses.

Notice the equivalent Stages for each Customer Statuses. For example, you created a Lead record with entitystatus of 7, you could set its entitystatus to 11 to convert the Lead record to Prospect.


var rec = nlapiLoadRecord('lead', 123);
rec.setFieldValue('entitystatus', 11);
nlapiSubmitRecord(rec);


By doing this, when user opens the record, it will now become a Prospect record. After changing the entitystatus of Lead to Prospect, you then have to use prospect as the record type when you access the newly converted record, otherwise you will get a Record Type Mismatch Error. It will also retain the same internal ID of the record when changing status from lead to prospect, and vice versa.

To convert Prospect to Lead:
var rec = nlapiLoadRecord('prospect', 123);
rec.setFieldValue('entitystatus', 7);
nlapiSubmitRecord(rec);

* This can also be applied to converting records from prospect or lead to customer.

Note that when using nlapiCreateRecord to create a Lead, Prospect or Customer, you have to take note of the appropriate record type internal ID to use when setting the entitystatus field value, otherwise you will get an Invalid entitystatus reference key error.

1 comment:

  1. Any idea where to look for possible causes of this:

    I have a customer status that I have edited to correspond to the "Customer" stage. However, whenever I assign that status my record gets converted to a "Prospect". I've double checked my status and ensured that it is indeed mapped to the "Customer" stage but I can't get it to work. Any thoughts?

    ReplyDelete