Creating a Custom Action in Lightning Conductor

A Step-by-Step Guide to Repurposing Built-in Actions for Bulk Field Updates

Creating a Custom Action in Lightning Conductor

This guide provides the steps to repurpose an existing built-in action into a "Change Value" action. By using the "Delete" action code as a template, you can perform bulk updates to item fields without writing code from scratch.

The Actions section of the Display tab in the Lightning Conductor's configuration wizard becomes available when you have set Allow selecting rows to either Single or Multiple Selection. Click on the + within the Actions section to add an action.

Technical Requirements

For simple implementation: This process is of an existing template; no development experience is required to follow the steps below.

For deep implementation: If you need to troubleshoot, debug, or expand the functionality beyond changing a field value, Programming/JavaScript knowledge will be required to understand the specific operations occurring in each line of the code, this isn't something we can help you with standard support. 

The Modification Process

You can see our pre-built JavaScript code by selecting one of the pre-built actions in the Lightning Conductor:

We will use the existing Delete action as a starting point because it already includes the necessary JSOM (JavaScript Object Model) requests. Follow these specific steps to repurpose it:

1. Update UI Messages and Variable Names

To ensure your custom action reports status correctly, perform a "Find and Replace" for the following:

Messages: Change "Deleting selected items..." to "Updating selected items..." and update error messages from "Failed deleting..." to "Failed updating...".

Variables: Rename deletionCount to updateCount throughout the entire script.

Functions: Rename finishDeleting to finishUpdating throughout the entire script.

2. Implement the Core Change

The actual logic to modify a field is performed by this specific command. Replace the item.recycle(); line with:

item.set_item("FieldName", "NewValue");

Note: Replace FieldName with the internal name of the column (e.g., "Status") and NewValue with the desired value (e.g., "Request Approval").

Code Template

Below is the code template reflecting the modifications described above:

startProcessingCallback("Updating selected items...");
var updateCount = 0;
var successCount = 0;
var lastError = undefined;

var finishUpdating = function(){
   if(lastError === undefined){
       finishProcessingCallback(true,true);
   } else {
       errorCallback(String.format("Failed updating some items.<br/>Error Details: {0}",lastError));
       if(successCount > 0){
           window.setTimeout(function(){finishProcessingCallback(true,true);}, 5000);
       }
   }
};

selectedItems.forEach(function(selectedItem){
   ++updateCount;
   requestExecutor.executeClientContext(function(){
       var context = new SP.ClientContext(selectedItem["_lt_ParentWebURL"]);
       var item = context.get_web().get_lists().getById(selectedItem["_lt_ParentListId"]).getItemById(selectedItem["ID"]);
       
       // This line modifies the item field
       item.set_item("FieldName", "NewValue"); 
       
       return context;
   },function(){
       --updateCount;
       ++successCount;
       if(updateCount == 0) finishUpdating();
   },
   function(sender,args){
       lastError = args.get_message();
       --updateCount;
       if(updateCount == 0) finishUpdating();
   });
});

 

Please feel to reach out to [email protected] if you have any questions, we would be more than happy to help. 

JavaScript
startProcessingCallback("Updating selected items...");
var updateCount = 0;
var successCount = 0;
var lastError = undefined;

var finishUpdating = function(){
    if(lastError === undefined){
        finishProcessingCallback(true,true);
    } else {
        errorCallback(String.format("Failed updating some items.<br/>Error Details: {0}",lastError));
        if(successCount > 0){
            window.setTimeout(function(){finishProcessingCallback(true,true);}, 5000);
        }
    }
};

selectedItems.forEach(function(selectedItem){
    ++updateCount;
    requestExecutor.executeClientContext(function(){
        var context = new SP.ClientContext(selectedItem["_lt_ParentWebURL"]);
        var item = context.get_web().get_lists().getById(selectedItem["_lt_ParentListId"]).getItemById(selectedItem["ID"]);
        
        // This line modifies the item field
        item.set_item("FieldName", "NewValue"); 
        
        return context;
    },function(){
        --updateCount;
        ++successCount;
        if(updateCount == 0) finishUpdating();
    },
    function(sender,args){
        lastError = args.get_message();
        --updateCount;
        if(updateCount == 0) finishUpdating();
    });
});

Was this article helpful?

Can’t find what you’re looking for?

Our world-class Customer Success team is here for you.

Contact Support