Form Preview Popup & SLA Not Triggering

yana7
Tera Contributor

I need help with a customization. I want to add a popup that previews the form data before submission. Also, the SLA condition I set up isn't triggering correctly. Can anyone help me?

Condition Existing :

UI Action - Ready to Work

Script

new StateFlow().processFlow(current, '3530e4b8d7102100bbc783e80e6103fe', 'manual');
// Moved redirect logic from state flow to UI Action
action.setRedirectURL(current);

 

SLA is triggering

yana7_0-1721742772041.png

 

PROBLEM >>>

I need help with a customization. I want to add a popup that previews the form data before submission. Also, the SLA condition I set up isn't triggering correctly. Can anyone help me?

yana7_1-1721742805040.png

 

yana7_2-1721742813573.png

 

All the changes I made :

UI Action - Ready For Work

function showPage() {
// Fungsi validasi untuk memeriksa field mandatory
function validateFields() {
// Periksa setiap field mandatory secara langsung
if (g_form.getValue('asset') === '') {
g_form.addErrorMessage('Please fill out the Asset field.');
return false;
}
if (g_form.getValue('location') === '') {
g_form.addErrorMessage('Please fill out the Location field.');
return false;
}
if (g_form.getValue('category') === '') {
g_form.addErrorMessage('Please fill out the Category field.');
return false;
}
if (g_form.getValue('subcategory') === '') {
g_form.addErrorMessage('Please fill out the Subcategory field.');
return false;
}
if (g_form.getValue('priority') === '') {
g_form.addErrorMessage('Please fill out the Priority field.');
return false;
}
if (g_form.getValue('u_type') === '') {
g_form.addErrorMessage('Please fill out the U_type field.');
return false;
}
if (g_form.getValue('short_description') === '') {
g_form.addErrorMessage('Please fill out the Short Description field.');
return false;
}

return true; // Semua field mandatory terisi
}

// Panggil fungsi validasi sebelum menampilkan preview
if (!validateFields()) {
return; // Jika validasi gagal, hentikan eksekusi
}

// ... Code untuk mendapatkan data dan menampilkan preview ...

// Gunakan GlideRecord untuk mendapatkan data dari tabel lain
var grAsset = new GlideRecord('alm_asset');
grAsset.get(g_form.getValue('asset'));
var machineName = grAsset.getValue('display_name');

var grModel = new GlideRecord('cmdb_model_category');
grModel.get(grAsset.getValue('model_category')); // Dapatkan model_category dari asset
var machineCat = grModel.getValue('name');

var grLocation = new GlideRecord('cmn_location');
grLocation.get(g_form.getValue('location'));
var lokasi = grLocation.getValue('name');

var grUser = new GlideRecord('sys_user');
grUser.get(g_form.getValue('opened_by'));
var firstName = grUser.getValue('first_name');
var lastName = grUser.getValue('last_name');
var user = firstName + ' ' + lastName;

// Gunakan fungsi getDisplayValue untuk mendapatkan label dari choice field
var choiceLabelState = g_form.getDisplayValue('state') || "Draft";
var choiceLabelPriority = g_form.getDisplayValue('priority');

// Contoh penggunaan label choice
console.log("State Label:", choiceLabelState);
console.log("Priority Label:", choiceLabelPriority);

showPreviewModal({
machineName: machineName,
machineCat: machineCat,
lokasi: lokasi,
user: user,
choiceLabelState: choiceLabelState,
choiceLabelPriority: choiceLabelPriority,
});
}

function showPreviewModal(data) {
var modal = new GlideModal('preview_work_order');
modal.setTitle('Work Order Preview');
modal.setSize(700, 400);

// Set preferences for the UI Page
modal.setPreference('table_name', g_form.getTableName());
modal.setPreference('sys_id', g_form.getUniqueValue());
modal.setPreference('user', g_user.getFullName());
modal.setPreference('number', g_form.getValue('number'));
modal.setPreference('opened_at', g_form.getValue('opened_at'));

// Gunakan data yang sudah diambil sebelumnya
modal.setPreference('opened_by', data.user);
modal.setPreference('machine', data.machineName);
modal.setPreference('machine_category', data.machineCat);
modal.setPreference('location', data.lokasi);

modal.setPreference('category', g_form.getValue('category'));
modal.setPreference('priority', data.choiceLabelPriority);
modal.setPreference('sub_category', g_form.getValue('subcategory'));
modal.setPreference('state', data.choiceLabelState);
modal.setPreference('type', g_form.getValue('u_type'));
modal.setPreference('planned', g_form.getValue('planned'));
modal.setPreference('short_description', g_form.getValue('short_description'));
modal.setPreference('description', g_form.getValue('description'));

modal.render();
}

 

UI Pages - preview_work_order

Button Ready to Work

Html

<button class="btn btn-primary" id="readyToWorkButton" onclick="readyFlow()">Ready to Work</button>

 

UI pages - Client Script

function readyFlow() {
var confirmMessage = "Are you sure to continue?";
if (confirm(confirmMessage)) {
// Simpan formulir jika ada perubahan (sesuaikan dengan logika UI Page Anda)
if (typeof g_form != 'undefined' && g_form) {
g_form.save();
}

processStateFlow();

// Pastikan GlideDialogWindow ada sebelum di-destroy
if (typeof GlideDialogWindow != 'undefined') {
GlideDialogWindow.get().destroy();
}
}
}

// Fungsi untuk memanggil Processing Script dengan GlideAjax
function processStateFlow() {
var ga = new GlideAjax('TriggerStateFlow');
ga.addParam('sysparm_name', 'processStateFlow');
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());

ga.getXMLAnswer(function(answer) {
console.log(answer);
// Refresh atau redirect halaman jika perlu
location.reload();
});
}

 

 

My Script Include

var TriggerStateFlow = Class.create();
TriggerStateFlow.prototype = {
initialize: function() {
},

processStateFlow: function() {
var sysId = this.getParameter('sysparm_sys_id'); // Ambil sys_id record

// Jalankan State Flow
new StateFlow().processFlow(sysId, '3530e4b8d7102100bbc783e80e6103fe', 'manual');

return 'Success'; // Optional: kirim pesan sukses ke client
},

// Helper function untuk mengambil parameter
getParameter: function(name) {
return (typeof input !== 'undefined') ? input[name] : '';
},

type: 'TriggerStateFlow'
};

 

 

I also tried triggering the state flow using a Business Rule, but the SLA still wasn't starting. Here's the code from my Business Rule: 

(function executeRule(current, previous /*null when async*/ ) {
new StateFlow().processFlow(current, '3530e4b8d7102100bbc783e80e6103fe', 'manual');
// Moved redirect logic from state flow to UI Action
action.setRedirectURL(current);

})(current, previous);
 
 
0 REPLIES 0