Formatting Data in SalesLogix Mobile Customizations

When adding custom fields to SalesLogix Mobile, you’ll often want to do things to the value, instead of just displaying it as-is. There are many built-in formatting functions, or renderers, available in the out-of-the-box SalesLogix Mobile platform, but what if you need to do something custom? Let’s take a look at what built-in formatting functions there are as well as how to create you own custom formatting function on the fly.

View the SalesLogix Mobile Developer series index

Where/how do you use formatting for a custom field in mobile?

First of all, what are formatting functions (or renderers)? Simply put, a formatting function is a function that takes a value and changes it so it is formatted differently than the raw data value. A format function can do things like take a phone number, stored as 8005551212 and format it like a phone number like (800) 555-1212. A format function can take a numeric value like 6543.21 and format it like $6,543.21. They are also called renderers when you’re using them. If you’re adding a field that is a phone number, you’ll add a “renderer” to tell it to format the value as a phone number like this:

this.registerCustomization('detail', 'account_detail', {
    at: function (row) { return row.name == 'Type'; },
    type: 'insert',
    where: 'after',
    value: {
        name: 'SecretPhone',
        property: 'SecretPhone',
        label: 'secret phone',
        renderer: Mobile.SalesLogix.Format.phone
    }
});

Built-in Formatting Options

There are a lot of built-in renderers. Some trim spaces from the value, some format the value like a hyperlink, and some are a bit more complex too. You can see the entire list of available formatting functions on the Argos SDK wiki:

Built-In Templates & Formatting Functions

You can see the code for these built-in functions as well. If you noticed on the page linked above, some of the formatting functions are part of the Argos SDK, while other are implemented in the argos-saleslogix product itself (also note that they can all be referenced via Mobile.SalesLogix.Format). To see the ones implemented in argos-saleslogix, navigate in your development environment to productsargos-saleslogixsrc and look for the Format.js file. The ones implemented in the Argos SDK can be found in the Format.js file in argos-sdksrc. If you open up those files, you can see that most of the formatting functions take in a single parameter and then return a string (the formatted result).

How do you create a custom formatting function?

It’s easy enough to create formatting functions on the fly. Keeping in mind that it takes a single parameter and returns a string. If you refer back to the code in this article, the sample where you’ll see the renderer property set to Mobile.SalesLogix.Format.phone. Well, Mobile.SalesLogix.Format.phone is a function. It’s set as the value of the renderer property, but it’s still a function. Rather than set a predefined function for the renderer, we can just create one in-line. For example, let’s say we have some “customer code” stored in the Account entity and that we can launch a URL including this code to go to some other website and see tickets for that customer code. If we add this in mobile, all we have is the code, so we’ll use a format function to format this code value as the URL we want to launch, and the user will just see the code itself as a hyperlink. Here’s how we do that:

this.registerCustomization('detail', 'account_detail', {
    at: function (row) { return row.name == 'Type'; },
    type: 'insert',
    where: 'after',
    value: {
        name: 'CustomerCode',
        property: 'CustomerCode',
        label: 'customer code',
        renderer: function(val) {
                    return '<a href="http://somewebsite.com/orders?customerCode=' + val + '">' + val + '</a>;
                }
    }
});

Not too bad, you can see all we need to worry about is taking a single parameter and returning a string. Easy. The user will see the customer code as a hyperlink and when clicked it will launch the URL.

View the SalesLogix Mobile Developer series index

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) news and product updates!

You have Successfully Subscribed!