From MobileX for Sage CRM Help
Jump to: navigation, search

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