Server: Difference between revisions
Crmtogether (talk | contribs) (Created page with "The server plugin is stored in "js\\plugins\\PLUGINNAME\\server\\FILENAME.js if (params.EntityId) { var sql = "select pers_emailaddress...") |
Crmtogether (talk | contribs) No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The server plugin is stored in "js\\plugins\\PLUGINNAME\\server\\ | 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 = | var sql = | ||
"select pers_emailaddress \ | "select pers_emailaddress \ | ||
from vsummaryperson \ | from vsummaryperson \ | ||
where pers_personid={0}"; | where pers_personid={0}"; | ||
sql = clr.System.String.Format(sql, params.EntityId); | sql = clr.System.String.Format(sql, params.EntityId); | ||
var jsonResult = SQLJSONSerializer.ExecuteQueryToJSON(sql, false); | var jsonResult = SQLJSONSerializer.ExecuteQueryToJSON(sql, false); | ||
var jsonObject = eval(jsonResult); | 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\\ | 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 = { | var emailSettings = { | ||
to: jsonObject[0].pers_emailaddress, | to: jsonObject[0].pers_emailaddress, | ||
From: "uname@server.com", | From: "uname@server.com", | ||
subject: " | subject: "New Order", | ||
body: emailBody, | body: emailBody, | ||
host: "smtp.server.com", | host: "smtp.server.com", | ||
Line 33: | Line 34: | ||
pEnableSsl: 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); | |||
'''Method''': DeleteRecord | |||
'''Params''': | |||
string tableName, string whereClause) | |||
'''Method''': ExecSQL | |||
'''Params''': | |||
string sql |
Latest revision as of 09:21, 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);
Method: DeleteRecord
Params:
string tableName, string whereClause)
Method: ExecSQL
Params:
string sql