Import into Sage CRM: Difference between revisions

From Accelerator for SageCRM
(Created page with "Using JINT mode you can insert data. The example below creates a Company and Person record. Then it updates the Company making the Contact the Primary contact for the Company. You can see use of the method "getID" which allows you to map SageCRM Lookup record Codes. ---- '''SAMPLE SCRIPT''' var account_name = "Acme Consulting"; var _source = "Import"; var _status = "Active"; //get any lookup code values (useful if mapping from another system w...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Using JINT mode you can insert data. The example below creates a Company and Person record.  
Using JINT mode you can insert data. The example below creates and Company and Person record. Then it updates the Company making the change in Company Name (Comp_Name).


Then it updates the Company making the Contact the Primary contact for the Company.
SAMPLE SCRIPT


 
  var company_name = "Perfect Company";
You can see use of the method "getID" which allows you to map SageCRM Lookup record Codes.
  var company_status = "Active";
----
  var company_type = "Prospect";
 
  var company_sector = "Finance";
 
  var company_primary_address_postal_code = "18";
'''SAMPLE SCRIPT'''
  //get any guid values
 
  var company_primary_addressID = di.getID("Address",company_primary_address_postal_code);
    var account_name = "Acme Consulting";
  var sageRecord = SageCRMRecord('Company');
 
  sageRecord.Set("Comp_Name", company_name);
    var _source = "Import";
  sageRecord.Set("Comp_Status", company_status);
 
  sageRecord.Set("Comp_Type", company_type);
    var _status = "Active";
  sageRecord.Set("Comp_Sector", company_sector);
 
  sageRecord.Set("Comp_PrimaryAddressId", company_primary_addressID);
    //get any lookup code values (useful if mapping from another system where then code and translation do not match)
  var companyFilter="Comp_Name eq '"+company_name+"'";
 
  var sRecord=di.querydb("Company",companyFilter,"Comp_CompanyId");
    var comp_source = di.'''getLookup'''("comp_source",_source);
  var companyId=null;
 
  if (sRecord && sRecord.Rows.Count==1) {
    var comp_status  = di.'''getLookup'''("comp_status ",_status);
    //only do if count is one
 
    var updated=sageRecord.Update(sRecord.Rows[0]['Comp_CompanyId']);
    var SageCRMRecordObj= '''SageCRMRecord'''('Company');
  }else if (sRecord && sRecord.Rows.Count==0){
 
  sageRecord.Set("Comp_Name", company_name);
    '''SageCRMRecordObj'''.Set("comp_source", comp_source);
  var newId=sageRecord.Insert();
 
  }else{
    '''SageCRMRecordObj'''.Set("comp_status", comp_status);
  di.display("****Duplicate Company Found****:"+company_name);
 
  }
var accountFilter="Name eq '"+account_name+"'";
 
var cRecord=di.querydb("Account",accountFilter,"Id");
 
var accountId=null;
 
if (cRecord && cRecord.Rows.Count==1)
 
{
 
    //only do if count is one
 
    var updated=creatioRecord.Update(cRecord.Rows[0]['Id']);  
    var newCompanyId=SageCRMRecordObj.Insert();
 
 
    var SageCRMRecordObjP= '''SageCRMRecord'''('Person');
 
    '''SageCRMRecordObjP'''.Set("Pers_companyid",newCompanyId);
 
    '''SageCRMRecordObjP'''.Set("pers_firstname","Michael");
 
    '''SageCRMRecordObjP'''.Set("pers_lastname","Scalea");
 
    var newContactId='''creatioRecord_contact'''.'''Insert'''();
 
    var '''creatioRecord_ac''' = '''CreatioRecord'''('Account');
 
    '''creatioRecord_ac'''.Set("PrimaryContactId",newContactId);
 
    '''creatioRecord_ac'''.'''update'''(newId);
 
}else{
 
    di.display("****Duplicate Account Found****:"+account_name);
 
}
 
----
SetNumeric example
 
So whenever we wants to set value as Numeric/Float then we we need to use creatioRecord.SetNumeric('Price',12.40);
 
EG
 
var creatioRecord = CreatioRecord('Product');
 
creatioRecord.Set('Name', 'TestProductName7');
 
creatioRecord.Set('Code', 'Test007');
 
creatioRecord.SetNumeric('Price', 15.30);
 
var newId=creatioRecord.Insert();
 
di.display(newId);
 
[[File:Jint creatio demo.png]]

Latest revision as of 11:44, 2 March 2026

Using JINT mode you can insert data. The example below creates and Company and Person record. Then it updates the Company making the change in Company Name (Comp_Name).

SAMPLE SCRIPT

  var company_name = "Perfect Company";
  var company_status = "Active";
  var company_type = "Prospect";
  var company_sector = "Finance";
  var company_primary_address_postal_code = "18";
  //get any guid values
  var company_primary_addressID = di.getID("Address",company_primary_address_postal_code);
  var sageRecord = SageCRMRecord('Company');
  sageRecord.Set("Comp_Name", company_name);
  sageRecord.Set("Comp_Status", company_status);
  sageRecord.Set("Comp_Type", company_type);
  sageRecord.Set("Comp_Sector", company_sector);
  sageRecord.Set("Comp_PrimaryAddressId", company_primary_addressID);
  var companyFilter="Comp_Name eq '"+company_name+"'";
  var sRecord=di.querydb("Company",companyFilter,"Comp_CompanyId");
  var companyId=null;
  if (sRecord && sRecord.Rows.Count==1) {
   	//only do if count is one
   	var updated=sageRecord.Update(sRecord.Rows[0]['Comp_CompanyId']);
  }else if (sRecord && sRecord.Rows.Count==0){
  	sageRecord.Set("Comp_Name", company_name);
  	var newId=sageRecord.Insert();
  }else{
  	di.display("****Duplicate Company Found****:"+company_name);
  }