10,727
edits
(→Lookup) |
|||
Line 1,254: | Line 1,254: | ||
# Click '''New View''' and enter the following parameters, then click '''OK'''.<br>[[File:Create a new lookup view.png]] | # Click '''New View''' and enter the following parameters, then click '''OK'''.<br>[[File:Create a new lookup view.png]] | ||
=== Independent lookup === | |||
This kind of lookup can be used from [[form]]s, [[view]]s, [[home screen]], or HTML files. It doesn’t require the use of detail view object, so you can create a lookup or multilookup from an HTML file and set what view you want to see. The best part is adding a [[FetchXML]] filter to view. | |||
Each lookup object mentioned in the first section contains a method to add FetchXML filter. Please check this reference to find out more about what method we talk about. The method is called addEntityFilter. Keep in mind that the fetch filter simply adds another filter that is described by fetch. | |||
https://www.resco.net/javascript-bridge-reference/#MobileCRM_UI_MultiLookupForm_addEntityFilter | |||
Another important thing to know is how to define views available for selection in the app. | |||
# | [[File:View selector in the app.png|150px]] | ||
# | |||
For this, we can use addView method. Each view that we add using this method will be available in the selector. | |||
https://www.resco.net/javascript-bridge-reference/#MobileCRM_UI_LookupForm_addView | |||
==== Normal LookUp form ==== | |||
This is the normal lookup form that displays one view form. We use it to select one unique value for the lookup. | |||
The code from reference page: https://www.resco.net/javascript-bridge-reference/#MobileCRM_UI_LookupForm_show | |||
[[File:JSBridge Guide 031.png|600px]] | |||
==== MultiLookUp form ==== | |||
Unlike in a normal lookup, users can select multiple items in a multilookup form. We receive the selected items in a success callback. After tapping the back button, the callback is executed. If all operations were successfully done, we get callback to success, otherwise to failure. | |||
==== Custom M:N relationship MultiLookup form ==== | |||
If a user has entities that can represent an M:N relationship, this lookup is the best way how to achieve this. The behavior of lookups can be almost completely controlled by JSBridge. | |||
For example, we start from one entity (Appointment). We want to create a display in this lookup on the right side that doesn’t have any reference to appointments. It is just an in-the-middle ‘Table’ between M:N relationship entities, but we need to use the middle point data from appointment to filter correct data in right side of the lookup. We are able to add entity filter that will use in fetch this appointment's values. For example, use the ''starts_on'' field in the filter.It can look like this. | |||
<syntaxhighlight lang='js'> | <syntaxhighlight lang='js'> | ||
var multiLookup = new MobileCRM.UI.MultiLookupForm("middleEntityName"); | |||
var filter = '<fetch version="1.0">' + | |||
'<entity name="middleEntityName">' + | |||
'<condition attribute="starts_on" operator="on-or-after" value="' + appointment.startson + '" />' + | |||
'</entity>' + | |||
'</fetch>'; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
You might run into this problem: Since we create an M:N relationship and this entity doesn’t know anything about appointments, it is not easy to set up what we want to see on the right side. In our case, it is the third object that is created with the use of the selected values and contains a reference to an appointment. So the best way is to set the data source by using an array of references of the third type entity object, which refers to this appointment. | |||
Type: https://www.resco.net/javascript-bridge-reference/#MobileCRM_Reference[] | |||
The code from reference page: https://www.resco.net/javascript-bridge-reference/#MobileCRM_UI_MultiLookupForm | |||
[[File:JSBridge Guide 032.png|600px]] | |||
For example, the mentioned LookUp can be executed by using the button command in your HTML files. | |||
=== Dependent LookUp === | |||
This type of lookup is dependent on DetailView object, since we are talking about detail items that we defined as lookup fields. Currently, we have two types of lookup – opened in form or directly inline. Now we will describe the functionality for the type of detail view item lookup. | |||
'''DetailViewItem LookUp''' – From the name of the object, we can expect that it requires a detail view and a detail item. This lookup is bound on a lookup field item. For example, we are on the Contact entity form and the first element is an Account lookup field. Using this object we can create a custom filter and a view that is displayed when a user taps on this item. We have two types of lookup that we can bind on this item. The first is inline, the second displays a lookup form as mentioned before. | |||
==== Inline lookup === | |||
An example of an inline lookup is listed below. It uses methods like a normal lookup, and a custom filter based on an XML view. | |||
<syntaxhighlight lang='js'> | <syntaxhighlight lang='js'> | ||
</syntaxhighlight> | var customXMLView = | ||
'<fetch version="1.0">' + | |||
'<entity name="account">' + | |||
'<filter type="and">' + | |||
'<condition attribute="statuscode" operator="ne" value="2" />' + | |||
//'<condition attribute="address1_city" operator="eq" value="Bratislava" />' + | |||
'</filter>' + | |||
'<link-entity name="contact" alias="L0" from="parentcustomerid" to="accountid" link-type="inner">' + | |||
'<filter type="and">' + | |||
'<condition attribute="fullname" operator="eq" value="Custom contact name" />' + | |||
'</filter>' + | |||
</link-entity></entity></fetch>'; | |||
/// Create inline lookup setup | |||
inlineSetup = new MobileCRM.UI.DetailViewItems.LookupSetup(); | |||
LookUp.entities.push("account"); | |||
inlineSetup.addFilter("account", customXMLView); | |||
var dialogSetup = new MobileCRM.UI.DetailViewItems.LookupSetup();</syntaxhighlight> | |||
==== Dialog lookup ==== | |||
Dialog lookups open normal lookup forms. | |||
<syntaxhighlight lang='js'> | <syntaxhighlight lang='js'> | ||
/// Create dialog setup what behaves like LookUp form | |||
dialogSetup.addView("account", "Default", true); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
As we already mentioned, we have to get a detail view and bind these items. For this, we use EntityForm request object. The final phase is placing the items to specific positions. Refer to the link below to learn about the possibilities you have and parameters that need to be set if you use just dialog/inline lookup. | |||
<syntaxhighlight lang='js'> | <syntaxhighlight lang='js'> | ||
MobileCRM.UI.EntityForm.requestObject(function (entityForm) { | |||
/// <param name="entityForm" type="MobileCRM.UI.EntityForm"/> | |||
var dv = entityForm.getDetailView("General"); | |||
/// …. CODE OF ITEMS HERE | |||
/// Add lookups to specific position on view. | |||
dv.updateLinkItemViews(0, dialogSetup, inlineSetup, false); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Link: https://www.resco.net/javascript-bridge-reference/#MobileCRM_UI__DetailView_updateLinkItemViews | |||
== Questionnaire == | |||
<syntaxhighlight lang='js'> | <syntaxhighlight lang='js'> | ||
</syntaxhighlight> | </syntaxhighlight> |