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. 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
top.sfClient.NewAPIClient("DocumentToolsClient") .getDocHeader(top.sfClient.GetPageQueryParameterByName("id")) .then(r=>console.log(r));
Classic API
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);})
Items on Document
Unfortunately, these API may return empty if the document item list is corrupt.
Using REST
top.sfClient.NewAPIClient("DocumentToolsClient") .getDocItems(top.sfClient.GetPageQueryParameterByName("id")) .then(r=>console.log(r)) .catch(x=>console.log(x,'\n',x.ThisReason));
Classic API
sfAPIGetRows("DocItem/1/DocItemNumber/Description", { dFilter: " " }) .then( (r) => console.log(JSON.parse(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.
Using REST
top.sfClient.NewAPIClient("DocumentToolsClient") .getDocHeader(top.sfClient.GetPageQueryParameterByName("id")) .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.
sfRunWorkflowScript("OnPayReqApproved")
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