Trace links mentioned in catalog variable

Puneet Hegde1
Tera Guru

Hi All,
Can you please let me know how to meet the requirements below?
Q) there is a catalogue variable which need to trace the link in it.
variable called:  X
variable type: rich text label
content: it has 6 hyperlinks one below the other

task need to achieve: there is a check box variable check only needs to check true if all the above hyperlinks has been clicked is there any way to achieve it

Thank you,
Puneet

2 ACCEPTED SOLUTIONS

@Puneet Hegde1 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Hi Ankur,
i have tried above method i was not able to capture the clicks I have added the code below for reference can you help me out where exactly I'm making mistake on the script.
Client control:

api.controller = function($scope, $timeout) {
var c = this;

// Ensure the form is fully loaded before accessing g_form
$timeout(function() {
if ($scope.page && $scope.page.g_form) {
console.log(" g_form is available!");

// Initialize click_counter if it's not already set
let currentValue = $scope.page.g_form.getValue('click_counter') || '0';
console.log("Initial Click Counter:", currentValue);

if (parseInt(currentValue) === 0) {
$scope.page.g_form.setValue('click_counter', '0');
}
} else {
console.error("g_form is NOT available inside the widget!");
}
}, 500); // Wait 500ms to ensure g_form is ready

// Function to track link clicks
c.trackClick = function(index) {
if ($scope.page && $scope.page.g_form) {
let clickedLinks = JSON.parse(sessionStorage.getItem('clickedLinks')) || [];

if (!clickedLinks.includes(index)) {
clickedLinks.push(index);
sessionStorage.setItem('clickedLinks', JSON.stringify(clickedLinks));
}

// Calculate updated count
let updatedCount = clickedLinks.length.toString();

// Ensure the update happens immediately
$scope.$applyAsync(function() {
$scope.page.g_form.setValue('click_counter', updatedCount);
});

console.log(" Updated Click Counter:", updatedCount);
} else {
console.error(" g_form is undefined - Unable to update click_counter");
}
};
};


Thank you in advance

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Puneet Hegde1 

difficult to achieve.

But you can use this approach

1) Create hidden string type variable and hide it using UI policy

2) Create a widget and add those links and define onclick function on it, that function will get value of the hidden variable and whenever click is performed it will increment the count. Create variable of type Custom and associate this widget

3) then use onSubmit catalog client script and see what's the count.

If the count is less than 6 then don't allow user to submit

check this link for Step 2

Pass values from a Widget to a Catalog item variable 

Basically you can use this syntax in client controller to get and set the variable value

$scope.page.g_form.setValue('var_name', 'yourValue');

$scope.page.g_form.getValue('var_name');

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,
thank you for suggesting a solution will definitely let you know does this works.

Thank you

@Puneet Hegde1 

the above has worked for me when I tried.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Puneet Hegde1 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader