KBA-01767: JavaScript Examples for Chrome Inspector


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


Use Chrome Inspector and these JavaScript snippets for starters.  Starting with late V2020 and V2021, use the REST example where possible.

Doc Revision Key (and Cost Impact):

Using REST

This snippet gives you ever field from xsfDocHeader and xsfDocRevision.  For example r.CostImpact and r.Title


Classic API

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

     .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);})

Items on Document

Unfortunately, these API may return empty if the document item list is corrupt.

Using REST


Classic API

sfAPIGetRows("DocItem/1/DocItemNumber/Description", { dFilter: " " }) 
     .then( (r) => console.log(JSON.parse(r)) )


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

             { 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’ ”



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) })

[] 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.

Using REST

     .then((r)=> { top.sfClient.GetDV("RouteName",r.LastRouteKey,undefined)
            .then( rn => console.log(`${rn} [${r.LastRouteKey}]`)) })

Classic API

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.


Older Versions

V2019 and V2020 Prior to build 7975

Avoid the REST API for documents.

Prior to 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: December 7, 2021 at 22:12 pm