How to access Source Element of Relationship while creating new records in Resco Mobile App

By | August 28, 2019

Introduction

Recently we had a business requirement in which we needed to create child records of Account entity from Parent Account record with pre-populated ‘Account Type’ field.

For example, we have an Option Set field (‘Account Type’ with four options Architects, Customers, Designers and Drafters) and four Entity Lists added on the Account Entity Form. Each Entity List has filter based on the ‘Account Type’ Option Set field and we want to pre-populate the ‘Account Type’ field on the child Account, when it is being created from one of the Entity Lists.

In Html (using JSBridge reference), we can get access to the relationship of the record (i.e. from which it is being created). And from that relationship we can retrieve the ‘Source Element’ of that record. This ‘Source Element’ provides the name of the ‘Entity List’ from which the record is being created. And we can use this for populating fields (i.e. ‘Account Type’) on Account. Also we can get access to all the properties of the parent record in relationship.

Note: If an entity record is created directly (i.e. not from any Entity List), then Source Element will be empty.

In order to achieve this we have followed the below steps:

1. We have added ‘Account Type’ field on the ‘Entity Form’ of Account entity. And renamed the ‘Entity Lists’ as the options of the ‘Account Type’ field as below.

Please refer below screenshot:

2. Then we have developed an Html file with JSBridge reference (Code is specified below) for retrieving the relationship of the record (from which it is being created) and populated the value of the ‘Account Type’ field based ‘Source Element’ of that relationship.

Please refer below screenshot:

Resco Mobile App

Note: ‘entityForm’ is an ‘Object’ which is retrieved from ‘RequestObject’ method of JSBridge reference file and ‘entityForm.relationship.sourceUIElement’ returns the ‘Name’ of the ‘EntityList’ defined/specified on the Entity Form. Also you will get access to all properties of the Parent record in entityForm.relationship object.

3. We have added the above Html file in Offline Html of Resco Mobile App. And then created an IFrame on ‘Entity Form’ of Account entity (for populating the ‘Account Type’ when the record is created from a specific Entity List of its Parent Account) and published the Project.

Please refer below screenshots:

Offline HTML:

Resco Mobile App

IFrame of Account Entity:

Resco Mobile App

4. After publishing the project, we have synced the Resco Mobile App and navigated to the Account entity record for adding a new child Account from ‘Customers’ Entity List.

Please refer below screenshots:

Resco Mobile App

 

Resco Mobile App

After clicking the plus button (i.e. +), the new Account entity form is loaded, and the value of the ‘Account Type’ was populated on the form.

Please refer below screenshot:

Resco Mobile App

And after saving the record, it is shown in ‘Customers’ Entity List.

Please refer below screenshot:

Resco Mobile App

Conclusion

You can use relationship property of ‘Entity Form Object’ for retrieving ‘Source Element’ in script (with JSBridge reference) while creating new record from Entity list in Resco Mobile App.

2 thoughts on “How to access Source Element of Relationship while creating new records in Resco Mobile App

  1. Aria Wilson

    What a fantastic post!!
    After reading this post I can clearly understand how to access source element in Resco app.
    I was looking for certain info dor a very long time. Finally, I found it.
    I will definitely share it with others.
    Thanks for sharing such a valuable post.

Comments are closed.