crm Methods
This class provides methods that allow you to use the Sage CRM JavaScript API.
Item Index
Methods
- addButton
- cacheTrans
- collapsiblePanels
- errorMessage
- getArg
- getArgs
- getTrans
- hideButton
- hideTab
- highlightCurrentField deprecated
- infoMessage
- installName
- installUrl
- installUrlJ
- map2QueryString
- markNonNumericFields
- markRequiredFields
- parseUrl
- printWindow
- queryString2Map
- ready
- sdata2Url
- sdataUrl
- showButton
- showTab
- url
- validateEmail
Methods
addButton
(
-
captionfamily
-
captioncode
-
linkURL
-
[Object.index]
)
-
captionfamily
-
captioncode
-
linkURL
-
[Object.index]


Adds a new action button. The name of the new button is translatable into other languages. You can use this method to add a print preview button or a button that opens a URL.
Parameters:
-
captionfamily
StringSets the caption family for the button name.
-
captioncode
StringSets the caption code for the button name.
-
linkURL
String | | ObjectSets the URL that opens when a user clicks the button.
-
[Object.index]
String optionalSpecifies the index of the table row where the new button is inserted.
When this parameter is omitted, the button is inserted into the last row.
Returns:
String
Examples:
// Adds a print preview button.
crm.addButton("print");
// Adds a button that opens the http://www.sagecrm.com URL in a new web browser window.
// The button ID is formed by using the caption code that is passed to the function.
// In this example, the button ID is #button-NewOrder.
crm.addButton("GenCaptions","NewOrder",
{"index": 2,
"href": "#",
click: function(){
window.open("http://www.sagecrm.com")
}
});
cacheTrans
(
-
options
)
-
options


Caches translations for later use. Accepts an object that contains caption family and optionally an array or caption codes. If no caption codes are specified, this method returns all translations for the caption family. This method executes asynchronously unless the async parameter is set to false, in which case the callback parameter is ignored.
Parameters:
-
options
ObjectSpecifies an object containing caption family and optionally an array of caption codes.
Returns:
Nothing
Examples:
// Caches translations of the error message whose caption code is TooManyRecords and that
// belongs to the caption family ampm.
crm.cacheTrans({'ampm': [], 'Errors' : ['TooManyRecords']}, function (translations) {
alert(translations['Errors']['TooManyRecords']);
});
collapsiblePanels
(
-
show
)
-
show

Adds a button that allows a user to collapse or expand a screen panel. The button is added to the right of the screen panel title.
Parameters:
-
show
BooleanSpecifies to add the button that collapses or expands the screen panel.
Returns:
Nothing
Examples:
// Adds the button that collapses or expands the screen panel.
crm.collapsiblePanels(true);
errorMessage
(
-
[message]
)
-
[message]


Adds a red banner displaying an error message to the page.
Parameters:
-
[message]
String optionalSpecifies the error message to show in the banner.
Returns:
String
Examples:
// Adds a red banner displaying the following error message: Test Message
crm.errorMessage("Test Message");
// Gets the current error message.
crm.errorMessage();
getArg
(
-
argument
-
url
)
-
argument
-
url


Gets a parameter value from a URL.
Returns:
String
Examples:
// Gets the value of the Act parameter in the URL returned by the crm.url() function.
crm.getArg("Act",crm.url());
getArgs
(
-
url
)
-
url


Gets an object containing all key-value pairs for a URL.
Parameters:
-
url
StringSpecifies the URL to inspect.
Returns:
Object
Examples:
// Gets an object containing all key-value pairs in the URL returned by the crm.url() function.
crm.getArgs(crm.url());
getTrans
(
-
family
-
code
)
-
family
-
code


Gets translations for a specified caption family and caption code.
Parameters:
Returns:
String
Examples:
// Gets translations for caption family Link_CompAddr and caption code Business.
crm.getTrans("Link_CompAddr","Business");
hideButton
(
-
id
)
-
id


Hides an action button with the specified ID.
Parameters:
-
id
StringSpecifies the ID of the action button to hide.
Returns:
Nothing
Examples:
// Hides an action button whose ID is Save.
crm.hideButton("Save");
hideTab
(
-
CaptionFamily
-
CaptionCode
-
action
)
-
CaptionFamily
-
CaptionCode
-
action


Hides a tab whose contents match the parameters passed to this method.
Parameters:
Returns:
String
Examples:
// Slowly hides a tab whose caption family is ColNames and caption code is SelfService.
crm.hideTab("ColNames", "SelfService", "fade");
// Immediately hides a tab whose caption family is ColNames and caption code is Self Service.
crm.hideTab("ColNames", "SelfService");
highlightCurrentField
(
-
color
)
deprecated
-
color

Highlights the field that is currently in focus.
Parameters:
-
color
StringSpecifies the color in which to highlight the field.
Examples:
None
infoMessage
(
-
[message]
)
-
[message]


Adds a purple banner displaying an information message to the page.
Parameters:
-
[message]
String optionalSpecifies the information message to show on the banner.
Returns:
String
Examples:
// Adds a purple banner displaying the following information message: Test Message
crm.infoMessage("Test Message");
// Gets the current information message.
crm.infoMessage();
installName
()


Gets the name of the Sage CRM application.
Returns:
String
Examples:
// Gets the name of the Sage CRM application in Web Server (IIS).
// For example, if the application URL is http://ServerName/SageCrmInstallation,
// this method returns SageCrmInstallation.
crm.installName();
installUrl
()


Gets the URL path to the eware.dll file.
Returns:
String
Examples:
// Gets the URL path to the eware.dll file.
// For example: http://ServerName/SageCrmInstallation/eware.dll
crm.installUrl();
installUrlJ
()


Gets the location of CRM Java endpoint.
Returns:
String
Examples:
// Gets the location of CRM Java endpoint.
// For example: http://ServerName/sdata/CrmInstance<u>j</u>
crm.installUrlJ();
map2QueryString
(
-
keyValPairs
)
-
keyValPairs


Gets a query string containing given key-value pairs.
Parameters:
-
keyValPairs
ObjectSpecifies an object containing the key-value pairs to include in the query string.
Returns:
String
Examples:
// Creates the following query string : "SID=159729525854568&Act=140&Mode=3&CLk=T&Key0=110"
crm.map2QueryString({SID: "159729525854568", Act: "140", Mode: "3", CLk: "T", Key0: "110"})
markNonNumericFields
(
-
CaptionFamily
)
-
CaptionFamily

Looks for numeric fields and inspects their value. If the field value is non-numeric, this method highlights the field in the specified color. This method ignores blank numeric fields.
Parameters:
-
CaptionFamily
StringSpecifies the color in which to highlight fields that contain non-numeric values.
Returns:
String
Examples:
// Looks for numeric fields that contain non-numeric values. Highlights such fields in red.
crm.markNonNumericFields("red");
markRequiredFields
(
-
color
)
-
color


Highlights all mandatory fields on a page using the specified color. Changes the tabindex attribute value, so that a user can press the TAB key to switch between the mandatory fields and the Save button on a page. Sets the input focus to the first mandatory field.
Parameters:
-
color
StringSpecifies the color in which to highlight mandatory fields. When this parameter is set to false, mandatory fields are not highlighted.
Returns:
String
Examples:
// Highlights all mandatory fields on a page in red.
crm.markRequiredFields("red");
parseUrl
(
-
url
-
parts
)
-
url
-
parts


Gets specified parts of an URL. parseUrl
Parameters:
-
url
StringSpecifies the URL whose parts you want to get.
-
parts
StringSpecifies which parts of the URL to get. This parameter can take the following values and their combinations: s a p q f
These values are explained below by using the example URL http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage.
Returns:
String
Examples:
// Gets the http:// string from the given URL and stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.parseUrl(url,{parts: 's'})
// Gets the http://www.sagecrm.com string from the given URL and stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.parseUrl(url,{parts: 'sa'})
// Gets the http://www.sagecrm.com/freetrial string from the given URL and
// stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.parseUrl(url,{parts: 'sap'})
// Gets the http://www.sagecrm.com/freetrial?lang=EN string from the given URL and
// stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.parseUrl(url,{parts: 'sapq'})
// Gets the http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage string from the given URL.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.parseUrl(url,{parts: 'sapqf'})
printWindow
()


Prints the contents of the current window.
Returns:
Nothing
Examples:
// Prints the contents of the current window.
crm.printWindow();
queryString2Map
(
-
url
)
-
url


Gets an object containing all key-value pairs for a URL.
Parameters:
-
url
StringSpecifies the URL to inspect.
Returns:
Object
Examples:
// Converts a URL to an object containing the key-value pairs.
// For example: {SID: "159729525854568", Act: "140", Mode: "3", CLk: "T", Key0: "110"}
var url = crm.url();
crm.queryString2Map(url);
ready
(
-
obj
)
-
obj


Runs the specified script after the page load event has been executed.
Parameters:
-
obj
FunctionSpecifies the script to execute.
Returns:
Object
Examples:
// Runs a script that highlights the cells in the orde_nettamt column whose
// value is greater than or equal to 5,000.00.
// The script is run after the page load event has been executed.
crm.ready(function() {
crm.grids().rows().filterWhere("orde_nettamt", "ge", "5,000.00").highlightCell("green");
})
sdata2Url
()


Gets the location of the SData 2.0 endpoint URL.
Returns:
String
Examples:
// Gets the location of the SData 2.0 endpoint URL: https://servername/sdata/crmj/sagecrm2/.
crm.sdata2Url();
sdataUrl
()


Gets the location of the SData endpoint URL.
Returns:
String
Examples:
// Gets the location of the SData endpoint URL: https://servername/sdata/crmj/sagecrm/-/.
crm.sdataUrl();
showButton
(
-
id
)
-
id


Shows an action button with the specified ID.
Parameters:
-
id
StringSpecifies the ID of the action button.
Returns:
String
Examples:
// Shows an action button whose ID is Save.
crm.showButton("Save");
showTab
(
-
CaptionFamily
-
CaptionCode
-
action
)
-
CaptionFamily
-
CaptionCode
-
action


Shows a tab whose contents match the parameters passed to this method.
Parameters:
Returns:
String
Examples:
// Slowly shows a tab whose caption family is ColNames and caption code is SelfService.
crm.showTab("ColNames", "SelfService", "fade");
// Immediately shows a tab whose caption family is ColNames and caption code is Self Service.
crm.showTab("ColNames", "SelfService");
url
(
-
[param1]
-
[options]
)
-
[param1]
-
[options]


Generates a Sage CRM URL.
Parameters:
-
[param1]
String | Number optionalSpecifies the URL. This parameter can take one of the following:
-
url
StringSpecifies the URL in the form of a string.
-
actionCode
NumberSpecifies the CRM action code to use.
-
aspURL
StringSpecifies the ASP page.
-
dotNetReference
StringSpecifies a .NET DLL and a DLL method to be called. Accepts the following format:
<DLL name>.<DLL method name>&<argument>=<value>.
-
-
[options]
Object optionalThe options below allow you to modify the returned URL by using key-value pairs.
-
[merge]
Boolean optionalIf you want to exclude the current context information from the returned URL, set this option to false.
-
[clearLocks]
Boolean optionalIf you want to exclude the CLk=T argument from the returned URL, set this option to false.
-
[ajax]
Boolean optionalIf you plan to use the returned URL for an Ajax request, set this option to true.
-
[parts]
String optionalSpecifies which parts of the URL to get. This option can take one or more of the following values: s a p q f
These values are explained below by using the example URL http://www.sagecrm.com/freetrial?lang=EN#WhyCHooseSage.s Specifies to include the scheme (http:// or https://). a Specifies to include the authority (www.sagecrm.com). p Specifies to include the path (/freetrial). q Specifies to include the query string (?lang=EN). f Specifies to include the fragment (#WhyChooseSage).
-
[asp]
String optionalIf you want to get a URL to an ASP page, use this option to specify the path to that page. For example, if the target ASP page has the name MyAspPage.asp and is located in the folder wwwroot\custompages\project, set this option to "/project/MyAspPage.asp".
-
[dll]
String optionalIf you want to get a URL to a DLL file created using the Sage CRM .NET API, use this option to specify the name of the DLL file. If you specify this option, you must also specify the [method] option.
-
[method]
String optionalIf you want to get a URL to a .NET DLL, use this option to specify the DLL method you want to call.
-
[act]
Number optionalIf you want to get a URL to a built-in action, use this option to specify the action code you want to invoke.
-
[args]
Boolean | Object optionalIf you want to add or replace arguments in the query string of the returned URL, use this option to specify those arguments. This option accepts a string or an object.
A string should have the following format:
"<arg1-name>=<arg1-value>&<arg2-name>=<arg2-value>".
An object should have the following format:
{ arg1-name: 'arg1-value', arg2-name: 'arg2-value' } -
[arg]
String optionalSpecifies the arguments whose values you want to return. For example, crm.url({arg: 'sid'}) returns the current session ID.
-
Returns:
String
Examples:
// Gets the http:// string from the given URL and stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.url(url,{parts: 's'})
// Gets the http://www.sagecrm.com string from the given URL and stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.url(url,{parts: 'sa'})
// Gets the http://www.sagecrm.com/freetrial string from the
// given URL and stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.url(url,{parts: 'sap'})
// Gets the http://www.sagecrm.com/freetrial?lang=EN string from the
// given URL and stores it in the url variable.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.url(url,{parts: 'sapq'})
// Gets the http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage string from the given URL.
var url = "http://www.sagecrm.com/freetrial?lang=EN#WhyChooseSage";
crm.url(url,{parts: 'sapqf'})
validateEmail
(
-
fieldId
)
-
fieldId


Checks if the specified field contains a valid email address. Returns a Boolean value indicating if the email address is valid or not.
Parameters:
-
fieldId
StringSpecifies the ID of the field that contains the email address to be validated.
Returns:
Boolean
Examples:
// Checks if the emai_emailaddressbusiness field contains a valid email address.
// If the email address is invalid, returns the message “This email is not valid.”
if (!crm.validateEmail("emai_emailaddressbusiness")) {
crm.errorMessage("This email is not valid");
}