Show:

crm Methods

This class provides methods that allow you to use the Sage CRM JavaScript API.

Methods

addButton
(
  • 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 String

    Sets the caption family for the button name.

  • captioncode String

    Sets the caption code for the button name.

  • linkURL String | | Object

    Sets the URL that opens when a user clicks the button.

  • [Object.index] String optional

    Specifies 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
)

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 Object

    Specifies 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
)

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 Boolean

    Specifies 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]
)

Adds a red banner displaying an error message to the page.

Parameters:

  • [message] String optional

    Specifies 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
)

Gets a parameter value from a URL.

Parameters:

  • argument String

    Specifies the parameter.

  • url String

    Specifies the URL to inspect.

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
)

Gets an object containing all key-value pairs for a URL.

Parameters:

  • url String

    Specifies 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
)

Gets translations for a specified caption family and caption code.

Parameters:

  • family String

    Specifies the caption family for which to get translations.

  • code String

    Specifies the caption code for which to get translations.

Returns:

String

Examples:

    // Gets translations for caption family Link_CompAddr and caption code Business.
    crm.getTrans("Link_CompAddr","Business");
hideButton
(
  • id
)

Hides an action button with the specified ID.

Parameters:

  • id String

    Specifies 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
)

Hides a tab whose contents match the parameters passed to this method.

Parameters:

  • CaptionFamily String

    Specifies the caption family of the tab to hide.

  • CaptionCode String

    Specifies the caption code of the tab to hide.

  • action String

    Causes the tab to disappear slowly. To do so, set this parameter value to fade.

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

Deprecated: This method is no longer supported. Use the Highlight method provided for the Fields class.

Highlights the field that is currently in focus.

Parameters:

  • color String

    Specifies the color in which to highlight the field.

Examples:

None

infoMessage
(
  • [message]
)

Adds a purple banner displaying an information message to the page.

Parameters:

  • [message] String optional

    Specifies 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
)

Gets a query string containing given key-value pairs.

Parameters:

  • keyValPairs Object

    Specifies 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
)

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 String

    Specifies 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
)

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 String

    Specifies 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
)

Gets specified parts of an URL. parseUrl

Parameters:

  • url String

    Specifies the URL whose parts you want to get.

  • parts String

    Specifies 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.

    • s String

      Gets the scheme (http:// or https://).

    • a String

      Gets the authority (www.sagecrm.com).

    • p String

      Gets the path (/freetrial).

    • q String

      Gets the query string (?lang=EN).

    • f String

      Gets the fragment (#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
)

Gets an object containing all key-value pairs for a URL.

Parameters:

  • url String

    Specifies 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
)

Runs the specified script after the page load event has been executed.

Parameters:

  • obj Function

    Specifies 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
)

Shows an action button with the specified ID.

Parameters:

  • id String

    Specifies the ID of the action button.

Returns:

String

Examples:

    // Shows an action button whose ID is Save.
    crm.showButton("Save");
showTab
(
  • CaptionFamily
  • CaptionCode
  • action
)

Shows a tab whose contents match the parameters passed to this method.

Parameters:

  • CaptionFamily String

    Specifies the caption family of the tab.

  • CaptionCode String

    Specifies the caption code of the tab.

  • action String

    When set to fade, causes the tab to appear slowly.

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]
)

Generates a Sage CRM URL.

Parameters:

  • [param1] String | Number optional

    Specifies the URL. This parameter can take one of the following:

    • url String

      Specifies the URL in the form of a string.

    • actionCode Number

      Specifies the CRM action code to use.

    • aspURL String

      Specifies the ASP page.

    • dotNetReference String

      Specifies a .NET DLL and a DLL method to be called. Accepts the following format:
      <DLL name>.<DLL method name>&<argument>=<value>.

  • [options] Object optional

    The options below allow you to modify the returned URL by using key-value pairs.

    • [merge] Boolean optional

      If you want to exclude the current context information from the returned URL, set this option to false.

    • [clearLocks] Boolean optional

      If you want to exclude the CLk=T argument from the returned URL, set this option to false.

    • [ajax] Boolean optional

      If you plan to use the returned URL for an Ajax request, set this option to true.

    • [parts] String optional

      Specifies 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 optional

      If 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 optional

      If 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 optional

      If you want to get a URL to a .NET DLL, use this option to specify the DLL method you want to call.

    • [act] Number optional

      If 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 optional

      If 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 optional

      Specifies 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
)

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 String

    Specifies 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");
    }

© Copyright Sage Technologies. All rights reserved.