Server: Difference between revisions

From MobileX for SageCRM
No edit summary
No edit summary
Line 46: Line 46:


Server API documentation
Server API documentation
----
SQLJSONSerializer Object
Method: InsertOrUpdateRecord
Params:
string tableName, string jsonRecord,
            string pimaryKeyField, string identifyingFields = null*
identifyingFields - is this is null then an insert is done
Example:
var var visitJSON = params.entitydata;
var recId = SQLJSONSerializer.InsertOrUpdateRecord("Entity", recordJSON, "prefix_entityid",
    entitydata.prefix_entityid? "prefix_entityid" : null);

Revision as of 09:18, 22 August 2018

The server plugin is stored in "js\\plugins\\PLUGINNAME\\server\\sendOrder.js

In the Client documentation page FILENAME=sendOrder

 EG
 "js\\plugins\\PLUGINNAME\\server\\sendOrder.js"

The code in the FILENAME is javscript and is executed.

 EG
 if (params.EntityId) {
   var sql =
       "select pers_emailaddress                               \
       from vsummaryperson                                \
       where pers_personid={0}";
   sql = clr.System.String.Format(sql, params.EntityId);
   var jsonResult = SQLJSONSerializer.ExecuteQueryToJSON(sql, false);
   var jsonObject = eval(jsonResult);
   //jsonObject runs the query and returns data
   //to access this data you can reference "jsonObject[0].pers_emailaddress"
   //GetFileContents - reads the file into a string
   var emailBody = email.GetFileContents("C:\\Program Files (x86)\\Sage\\CRM\\CRM\\WWWRoot\\CustomPages\\SageCRMWS\\js\\plugins\\PLUGINNAME\\server\\email.txt");
   //create an email object
   var emailSettings = {
       to: jsonObject[0].pers_emailaddress,
       From: "uname@server.com",
       subject: "New Order",
       body: emailBody,
       host: "smtp.server.com",
       port: "123",
       UserName: "uname@server.com",
       Password: "password",
       pIsBodyHtml: true,
       pEnableSsl: true
   }
   //sendEmail - sends an email based on the settings
   email.SendEmail(emailSettings.to, emailSettings.From, emailSettings.subject, emailSettings.body, emailSettings.host, emailSettings.port, emailSettings.UserName, emailSettings.Password, emailSettings.pIsBodyHtml, emailSettings.pEnableSsl);
   //this is displayed on screen by the Factory.msgbox method
   Response.Write('Email sent to: '+jsonObject[0].pers_emailaddress);
 }


The code is run on the server in the context of the IIS app.

This means that you have no real limits on what it can do. We do provide an API though from the app that is used to access CRM.

Server API documentation



SQLJSONSerializer Object

Method: InsertOrUpdateRecord

Params: string tableName, string jsonRecord,

           string pimaryKeyField, string identifyingFields = null*

identifyingFields - is this is null then an insert is done

Example:

var var visitJSON = params.entitydata;

var recId = SQLJSONSerializer.InsertOrUpdateRecord("Entity", recordJSON, "prefix_entityid",

   entitydata.prefix_entityid? "prefix_entityid" : null);