Based on user request in zenpage, i am running the method ConvertMDXtoJSON in background and loading the status in progressbar.
Below is my code.
ClassMethod ConvertMDXtoJSON(pMDX) As %String
{
Try
{
Do ..%SetBackgroundMethodStatus("Started",0)
set Params = ""
set pStatus = $$$OK
set RS = ##class(MS.Deepsee.MDX2JSON.ResultSet).%New()
set pStatus = RS.%PrepareMDX(pMDX)
return:$$$ISERR(pStatus) RS
set pStatus = RS.%ExecuteAsynch(.QueryKey,.Params,0)
s pCubeName="StockDetail"
// Gets progress Percentage
set prog= ##class(%DeepSee.ResultSet).%GetQueryStatus(pCubeName, QueryKey,.tComplete,.tSC,.tPending)
while (prog<100 )
{
set prog= ##class(%DeepSee.ResultSet).%GetQueryStatus(pCubeName, QueryKey,.tComplete,.tSC,.tPending)
Do ..%SetBackgroundMethodStatus("Percentage completed",tComplete)
}
}
Catch {}
set obj = RS.ToProxyObject(.st)
return:$$$ISERR(st) st
//$$$DynObjToJSON(obj)
Set tInitIO = $IO
// we MUST use %ISCJSONStream variable used by mnemonic space ^%ZEN.Auxiliary.jsonProvider.1 as output redirection container
set %ISCJSONStream=##class(%Stream.TmpCharacter).%New()
use tInitIO::("^%ZEN.Auxiliary.jsonProvider.1") // this routine – here as mnemonic space – is created during %ZEN.Auxiliary.jsonProvider class compilation
do ##class(%Library.Device).ReDirectIO(1)
$$$THROWONERROR(tSC,##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(obj))
If ##class(%Library.Device).ReDirectIO(0) Use tInitIO
do %ISCJSONStream.Rewind()
set sjson = %ISCJSONStream.Read()
Do ..%EndBackgroundMethod()
Q sjson
}
ClassMethod %OnMonitorBackgroundTask(pTaskID As %String, pStatus As %String, pPercentComplete As %Float)
{
Set pMsg = pStatus _ ": " _ +pPercentComplete _ "%"
if pPercentComplete>0
{
&js<
document.getElementById("Percentage").innerHTML='#(pMsg)#';
document.getElementById("prog").value='#(pPercentComplete)#';
>
}
}
ClassMethod %OnFinishBackgroundTask(pTaskID As %String)
{
//set ..Json = 1
#; Clear HTML component
&js<
document.getElementById("prog").value='100';
document.getElementById("Percentage").innerHTML='Finished';
document.getElementById('sframe').src="../msdeepsee/MS.Deepsee.Frame.cls"
>
}
After finishing the backgroundtask, loading a iframe. there i need to get the status(sjon).
Give me some suggestion.