KBA-01767: JavaScript Examples for Chrome Inspector

Note: This article applies only to versions of sfPMS prior to V2021

Question:

How can I get information from a document that is not displayed on the UI?

Answer:

Use Chrome Inspector and these JavaScript snippets for starters.

Doc Revision Key (and Cost Impact):

This snippet gives you the current document revision key and cost impact.  You can get any field from the current revision xsfDocRevision.

sfAPIGetFields("DocRevision/DocRevKey/0/CostImpact/RevNo")
         .done(function (r) { console.log(r);})

Other common fields include: DraftNumber, Created

Other common tables:

  • DocMasterDetail - sfAPIGetFields("DocMasterDetail/DocMasterKey/0/Subtype").done(function (r) { console.log(r);})

ItemTaskKey:

This snippet gives you current document item task data for a given item number.  You can get any field from  xsfDocItemTask.

sfAPIGetRows("DocItemTask/1/ProjEntity/AccountCategory/UOM", 
             { dFilter: " Parent.DocItemNumber ='0003' " })
       .done(function (r) { console.log(r) })

Other common fields include: ExpenseAmount, Subcontract, Quantity, Created, LinkedRFQKey, LinkedCCCKey, and DocItemKey.

To filter by Item Key, use dFilter: ” DocItemTask = ‘f34087e6-c842-4d30-b949-ebe0126baa42’ ”

Results:

[{“key“:”7158158d-fdf1-4c4e-a611-8199a6476353″,”ItemTaskKey“:”7158158d-fdf1-4c4e-a611-8199a6476353″,”ProjEntity“:”05000″,”AccountCategory“:”CUSTOM”,”UOM“:”HR”}]

Route Workflow Information:

This snippet gives you information of when a past route ran a workflow and what the script was.

sfAPIGetRows("DocRoute/1/Status/Acted/WorkflowScript", { dFilter: " WorkflowScript IS NOT NULL" })
       .done(function (r) { console.log(r) })

Has Document Posted

This snipped gives you information about record document posting events

sfAPIGetRows("DocPosting/1/PostingType/Posted", { dFilter: "true" })
.done(function (r) { console.log(r) })
Results:

[] means no postings have been recorded

[{“key”:”5b23759a-cb2b-4514-850a-b82fafe054ac”,”DocPostingKey”:”5b23759a-cb2b-4514-850a-b82fafe054ac”,“PostingType”:”EX”,”Posted”:”2018-02-23T10:58:04.273″}]  means that expenses were posted at the indicated date and time

On a budget revision or forecast, follow up with

sfAPIQuery("qDocPosting").done(function(r) {console.log(r);})

to see a single row indicating the number of posting(s) and the expense and revenue amounts.

Which Predefined Route was Used

This snippet gives you the predefined route key and if it is not null (?nv?), gets the name of the route.

sfAPIGetFields("DocMasterDetail/Title/0/LastRouteKey ")
    .done(function (r) { console.log(r); 
        if (!r.LastRouteKey.startsWith("?")) getDV("RouteName",r.LastRouteKey,null)
          .done(function(v) { console.log(v) })
        });

Run an ATC Workflow

This snippet triggers a workflow without having to achieve the internal trigger conditions.  You are responsible for determining that running the script is safe/appropriate.

sfRunWorkflowScript("OnPayReqApproved")

Older Versions (pre-V2019)

sfAPIGetFields and sfAPIGetRows simplify older calls and were added in V2019.  If these functions are not defined at your site then you can define them by pasting this into Chrome’s inspector console

function sfAPIGetFields(req) {
// usage table/key/0/field1/field2/.../fieldn
return GetJSONPX("get/{0}/{1}".format(sfWCC.dsCacheKey, req));
}
function sfAPIGetRows(req, options) {
// usage table/1/field1/field2/.../fieldn
return PostPX("GetRows/{0}/{1}".format(sfWCC.dsCacheKey, req),options);
}

KBA-01767; Last updated: June 29, 2020 at 13:39 pm