From MobileX for SageCRM

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

In the Client documentation page FILENAME=sendOrder


The code in the FILENAME is javscript and is executed.

 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: "",
       subject: "New Order",
       body: emailBody,
       host: "",
       port: "123",
       UserName: "",
       Password: "password",
       pIsBodyHtml: true,
       pEnableSsl: true
   //sendEmail - sends an email based on the settings
   email.SendEmail(, emailSettings.From, emailSettings.subject, emailSettings.body,, 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


 string tableName, string jsonRecord, string pimaryKeyField, string identifyingFields = null*

identifyingFields - is this is null then an insert is done


var var visitJSON = params.entitydata;

var recId = SQLJSONSerializer.InsertOrUpdateRecord("Entity", recordJSON, "prefix_entityid", entitydata.prefix_entityid? "prefix_entityid" : null);

Method: DeleteRecord


 string tableName, string whereClause)

Method: ExecSQL


 string sql