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
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";


'''SAMPLE SCRIPT'''
var company_sector = "Finance";


    var account_name = "Acme Consulting";
var company_primary_address_postal_code = "18";


    var _source = "Import";
//get any guid values


    var _status = "Active";
var company_primary_addressID = di.getID("Address",company_primary_address_postal_code);


    //get any lookup code values (useful if mapping from another system where then code and translation do not match)
var sageRecord = SageCRMRecord('Company');


    var comp_source = di.'''getLookup'''("comp_source",_source);
sageRecord.Set("Comp_Name", company_name);


    var comp_status  = di.'''getLookup'''("comp_status ",_status);
sageRecord.Set("Comp_Status", company_status);


    var SageCRMRecordObj= '''SageCRMRecord'''('Company');
sageRecord.Set("Comp_Type", company_type);


    '''SageCRMRecordObj'''.Set("comp_source", comp_source);
sageRecord.Set("Comp_Sector", company_sector);


    '''SageCRMRecordObj'''.Set("comp_status", comp_status);
sageRecord.Set("Comp_PrimaryAddressId", company_primary_addressID);


var accountFilter="Name eq '"+account_name+"'";
var companyFilter="Comp_Name eq '"+company_name+"'";


var cRecord=di.querydb("Account",accountFilter,"Id");
var sRecord=di.querydb("Company",companyFilter,"Comp_CompanyId");


var accountId=null;
var companyId=null;


if (cRecord && cRecord.Rows.Count==1)
if (sRecord && sRecord.Rows.Count==1) {
 
{


     //only do if count is one
     //only do if count is one


     var updated=creatioRecord.Update(cRecord.Rows[0]['Id']);
     var updated=sageRecord.Update(sRecord.Rows[0]['Comp_CompanyId']);
    var newCompanyId=SageCRMRecordObj.Insert();


}else if (sRecord && sRecord.Rows.Count==0){


     var SageCRMRecordObjP= '''SageCRMRecord'''('Person');
     sageRecord.Set("Comp_Name", company_name);


    '''SageCRMRecordObjP'''.Set("Pers_companyid",newCompanyId);
    var newId=sageRecord.Insert();
 
    '''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{
}else{


    di.display("****Duplicate Account Found****:"+account_name);
    di.display("****Duplicate Company Found****:"+company_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]]

Revision as of 11:42, 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);

}