Resco JavaScript Bridge: Difference between revisions

Jump to navigation Jump to search
Line 379: Line 379:


In the code above, we have provided the method loadDocumentBody with Note’s logical name (= annotation) and an existing annotation ID. The success callback will process the result so that it will find the HTML div element with id ‘img’ and inserts an image element containing the loaded data. They are stored as base64 string, therefore that’s specified first. Nothing else is required in fact – the image is then displayed on the page!
In the code above, we have provided the method loadDocumentBody with Note’s logical name (= annotation) and an existing annotation ID. The success callback will process the result so that it will find the HTML div element with id ‘img’ and inserts an image element containing the loaded data. They are stored as base64 string, therefore that’s specified first. Nothing else is required in fact – the image is then displayed on the page!
=== Access metadata information ===
Access to the metadata from JSBridge can serve you to verify what entities are part of the current project and what permissions does the current app user have. In the example below (that you can add to your home screen), there's a button that displays information about the permissions to a particular entity.
The button:
<syntaxhighlight lang='xml'>
<button id="checkAccountPermissions" onclick="checkAccountPermissions()">Display entity permissions</button>
</syntaxhighlight>
The script:
<syntaxhighlight lang='js'>
function checkAccountPermissions() {
    MobileCRM.Metadata.requestObject(function(metadata) {
        var my_entity_name = "resco_appointmentquestionnaire"
        var my_entity = metadata.getEntity(my_entity_name);
        if (my_entity) {
            if (!my_entity.isEnabled)
                MobileCRM.bridge.alert("The entity " + my_entity_name + " is not enabled in the project.");
            else {
                // validate CRUD permissions.
                var validCRUDStr = "";
                if (!my_entity.canCreate())
                    validCRUDStr += "Create NOT ALLOWED\n";
                if (!my_entity.canRead())
                    validCRUDStr += "Read NOT ALLOWED\n";
                if (!my_entity.canDelete())
                    validCRUDStr += "Delete NOT ALLOWED\n";
                if (!my_entity.canWrite())
                    validCRUDStr += "Update NOT ALLOWED\n";
                var msg = validCRUDStr.length > 0 ? validCRUDStr : "CRUD permission all allowed.";
                MobileCRM.bridge.alert(msg);
            }
        } else
            MobileCRM.bridge.alert("The entity " + my_entity_name + " is not part of the project.");
    }, MobileCRM.bridge.alert);
}
</syntaxhighlight>


== Controlling UI ==
== Controlling UI ==

Navigation menu