Loop through selected records in a Multi-Select view custom command with Resco Mobile CRM

You cannot create a form rule for your custom Multi-Select command which means that you will need to add some Offline HTML to execute your custom rule. To apply your custom rule you will need to add a new command to your view. In this case I have given it the name ‘custom_Test’.

*Note* You wont see the custom command unless you have attached an iFrame calling the custom command name.


Then you will need to link you Offline HTML to your view using the iFrame button.


You then call the custom command by using the function MobileCRM.UI.EntityList.onCommand(“custom_Test“, function (entityList)

Below is the complete code for looping through the selected view records:

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8" />
	<title>Work Order View Command</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="initial-scale=1, user-scalable=no" />
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="Cache-Control" content="no-store" />
	<script src="JSBridge.js"></script>
	<script src="app.js"></script>
</head>

<body>
	<script type="text/javascript">
	MobileCRM.UI.EntityList.onCommand("custom_Test", function(entityList) {
		/// <param name='entityList' type='MobileCRM.UI.EntityList'>
		var selectedEntities = entityList.context.entities;
		for(var i in selectedEntities) {
			var results = selectedEntities[i].id;
			updateWO(results);
		}
	}, true, null);

	function updateWO(results) {
		var workorder = new MobileCRM.DynamicEntity("fs_workorder", results);
		var WOprops = workorder.properties;
		WOprops.email_sent = true;
		workorder.save(function(error) {
			if(error) MobileCRM.bridge.alert("An error occurred: " + error);
			else {
				MobileCRM.bridge.alert("Email process has started");
			}
		});
	}
	</script>
</body>

</html>

The ‘selectedEntities‘ variable above holds the list of selected records. To update each record you will need to execute a for loop and retrieve the id of each selected record using ‘selectedEntities[i].id‘. Once you have the id of each record you will need to update them.

In this example I am updating the ‘fs_workorder‘ entity in my own function called ‘updateWO()‘ where I’m passing the id of each record and updating a field called ‘email_sent‘ to yes.

You can use this sample code and apply it to your own needs.

Leave a Reply

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