How to get the ‘Triggered By’ of FAM Process through Asset Transfer

 if (processIdValue == 'transfer') {
                            if (parametersObj.recsToProcess) {
                                Object.keys(parametersObj.recsToProcess).forEach(function (assetId) {
                                    log.debug("assetDetails", assetId)
                                    let journalId = toGetAssetTransferId(assetId)
                                    log.debug("journalId", journalId)
                                    // let journalId = parametersObj.journals || 'journalIdNotFound'; // Replace with actual logic if needed


                                    proplistObject[journalId] = {
                                        processId: processIdValue,
                                        triggeredBy: triggeredBy
                                    };
                                });
                                log.debug("Proplist Object for transfer", proplistObject);
                            }
                        }
function toGetAssetTransferId(assetId) {
        try {
            let customrecord_ncfar_deprhistorySearchObj = search.create({
                type: "customrecord_ncfar_deprhistory",
                filters: [
                    ["custrecord_deprhistasset", "anyof", assetId]
                ],
                columns: [
                    search.createColumn({
                        name: "internalid",
                        summary: "MAX",
                        label: "Internal ID"
                    }),
                    search.createColumn({
                        name: "internalid",
                        join: "CUSTRECORD_DEPRHISTJOURNAL",
                        summary: "MAX",
                        label: "Internal ID"
                    })
                ]
            });


            let searchResultCount = customrecord_ncfar_deprhistorySearchObj.runPaged().count;
            log.debug("customrecord_ncfar_deprhistorySearchObj result count", searchResultCount);


            let postingReference = null;


            customrecord_ncfar_deprhistorySearchObj.run().each(function (result) {
                // Retrieve the posting reference (journal ID)
                postingReference = result.getValue({
                    name: "internalid",
                    join: "CUSTRECORD_DEPRHISTJOURNAL",
                    summary: "MAX",
                });
                return true; // Continue the search
            });


            return postingReference;
        } catch (error) {
            log.error("Error in toGetAssetTransferId", error.message);
            return null;
        }
    }

Leave a comment

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