Customizing the SData Model for Entities in Infor CRM Mobile in Version 3.4 and Above

As of mobile 3.4, each entity has a model which describes the data to retrieve for it’s different views (detail, edit, list). The models can be customized in the same way as you register customizations for a view. In mobile versions previous to 3.4, you would use  methods, such as querySelect to add a new property to the SData query for a view. This method will still work, just like before, for backwards compatibility. However, modifying the model is the preferred way to do this in 3.4 and higher.

To add to the model, such as the contact model for the details view, you would add the following:

this.registerCustomization('models/detail/querySelect', 'contact_sdata_model', {
    at: function() { return true; },
    type: 'insert',
    where: 'after',
    value: 'SomeContactProperty'
});

That code adds the contact property SomeContactProperty to the fields retrieved via SData for the contact details view. It is the equivalent to the following method used in pre 3.4 mobile:

lang.extend(crm.Views.Contact.Detail, {
    querySelect: crm.Views.Contact.Detail.prototype.querySelect.concat([
        'SomeContactProperty'
    ])
});

Both of the code samples above accomplish the same, to include the contact property SomeContactProperty to the SData query for the Contact detail view. Also note, BOTH of those will still work in current mobile, although the first is the preferred method in 3.4 and later, adding to the querySelect is only there for backwards compatibility.

Also note, if you need to add an entity to the “include” part of the query, to include related entities in the query, you can register those in the model like this:

this.registerCustomization('models/detail/queryInclude', 'contact_sdata_model', {
    at: function() { return true; },
    type: 'insert',
    where: 'after',
    value: 'RelatedContactEntity'
});

You can replace things in the model as well by specifying type: ‘modify’ (or remove), such as the following to modify the orderBy for the query used in the contact list:

this.registerCustomization('models/queryModel', 'contact_sdata_model', {
    at: function(queryModel) { return queryModel.name === 'list'; },
    type: 'modify',
    value: {
        queryOrderBy: 'LastName desc'
    }
})

Obviously, for all of that, you can change the ‘models/detail/querySelect’ to ‘models/edit/querySelect’ or ‘models/list/querySelect’ to add properties to the query for the edit or list views as well.

One last thing, it is worth noting, for all of the above – adding fields to the querySelect, adding include entities, adding queryOrderBy fields to sort by, the value part can be arrays as well. There is no need to add one of the above sections for each and every field you’re adding. For example, in the first sample where we added SomeContactProperty to the querySelect for the contact model, if we wanted to also add AnotherProperty and OneMore to the model, we could do it all at once as an array:

this.registerCustomization('models/detail/querySelect', 'contact_sdata_model', {
    at: function() { return true; },
    type: 'insert',
    where: 'after',
    value: [
        'SomeContactProperty', 
        'AnotherProperty',
        'OneMore'
    ]
});

That will definitely cut down on some of those repetitive code blocks and make everything much cleaner.

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!