jMarshal
Mega Sage

I think you need to keep the code for the "Pin/Unpin" script in the actions for when you click on card...that way the "Next Button" client script has the parameters you're looking for (this is why it is sometimes the same parameters as a previous template -- they're present, but not getting passed by the Pin/Unpin as you desire).

I am using the same client script that was used on OOTB 'Next' Button Event in the Event Handler 

OOTB Next Button Click:

VoonaRohila_2-1686936462875.png

Card Selection Event click :

VoonaRohila_0-1686936818132.png

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
5x ServiceNow MVP

Yes, but you need the other one too (you need 3 events handlers for this, on the card selection click)

/**
 * @Param {params} params
 * @Param {api} params.api
 * @Param {any} params.event
 * @Param {any} params.imports
 * @Param {ApiHelpers} params.helpers
 */
function handler({
    api,
    event,
    helpers,
    imports
}) {
    let models = JSON.parse(JSON.stringify(api.state.models));
    let filter = JSON.parse(JSON.stringify(api.state.searchInfo.selectedFilter));
    let pinnedArray = models.pinned.split(",");

    //Update base models
    models.chgModels.forEach(function(model, index) {
        if (model.sysId === event.context.item.value.sysId) {
            let pinnedIndex = pinnedArray.indexOf(model.sysId);

            if (model.isPinned) {
                if (filter === 'pinned') {
                    models.chgModels.splice(index, 1);
                    --models.totalCards;
                } else {
                    model.isPinned = false;
                    model.pinIcon = [{
                        "icon""thumbtack-outline",
                        "label": models.pinLabels.pin
                    }];
                }
                if (pinnedIndex > -1) {
                    pinnedArray.splice(pinnedIndex, 1);
                }
            } else {
                model.isPinned = true;
                model.pinIcon = [{
                    "icon""thumbtack-fill",
                    "label": models.pinLabels.unpin
                }];
                pinnedArray.push(model.sysId);
            }
        }
    });

    models.pinned = pinnedArray.join();
    api.setState("models", models);

    api.emit("UPDATE_USER_PINNED_PREFERENCES", {});
}

which is on the pin/update card:

jMarshal_0-1686937306932.png



keep that action (execute client script pin unpin card) at the top of the "events" you copied from the next button.




Hi @jMarshal 

I tried and It's always taking the default change model on any card click.

VoonaRohila_0-1687156505755.png

Also added Card Click client script so that the values for 

selectedCard are being set but same issue.

VoonaRohila_1-1687159268217.png

 

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
5x ServiceNow MVP

Sorry - I am also quite new to UI Builder.

After further investigation - you definitely do not want the "Pin Unpin" there -- I believe that is specifically for the "Pinning" of change tiles, in the repeater container.

...and I went so far as to edit the "Card Click" action to include the client scripts of "close tab" and "next button" embedded in that action's client script...and it has the same symptoms as you describe, so I am at a loss.

Sorry, I wish I could be of more help - you definitely need to combine the scripts of all of the actions...but clearly more is needed, rather than just copying the variant and modifying the click action on the card to do "all the things" (that are done oob, with the next button).