I'm trying to create an entity group through SuiteScript based upon creation of some custom records. However, I'm getting an error:
You cannot define this group type using this search.
The search being used is a search for contact records, the entity group is for contact records. If I create the entity group through the UI, it allows the search to be used in a group, but not through script.
var user = nlapiGetUser();
var entityGroupName = custRec.getFieldValue("name");
var gcSearch = nlapiCreateSearch("contact", filters, columns);
gcSearch.setIsPublic(true);
var searchID = gcSearch.saveSearch("Contact Search: " + enityGroupName, "customsearch_contact_srch_" + custRecID);
var egRec = nlapiCreateRecord("entitygroup", { grouptype : "Contact" , dynamic : "T" , recordmode : "dynamic" });
egRec.setFieldValue("groupname", "Contact Group: " + entityGroupName);
egRec.setFieldValue("groupowner", user);
egRec.setFieldValue("restrictedtoowner", "F");
egRec.setFieldValue("parentgrouptype", "CustJob");
egRec.setFieldValue("savedsearch", searchID);
nlapiSubmitRecord(egRec, true, false);
What am I missing? I did try initializing the type as "contact" instead of "Contact", but then I get an error saying the search ID value is invalid.