I am trying to use printTask as shown below, but it's not going in the printResult function.
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">printImage</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> printTask<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> params <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>sentScale <SPAN class="operator token">==</SPAN> <SPAN class="number token">1000</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
printTask <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintTask</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
params<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>sentScale <SPAN class="operator token">==</SPAN> <SPAN class="number token">2500</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
printTask <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintTask</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
params<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">var</SPAN> template <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintTemplate</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
template<SPAN class="punctuation token">.</SPAN>format <SPAN class="operator token">=</SPAN> <SPAN class="string token">'JPG'</SPAN><SPAN class="punctuation token">;</SPAN>
template<SPAN class="punctuation token">.</SPAN>layout <SPAN class="operator token">=</SPAN> <SPAN class="string token">'MAP_ONLY'</SPAN><SPAN class="punctuation token">;</SPAN>
template<SPAN class="punctuation token">.</SPAN>preserveScale <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN>
params<SPAN class="punctuation token">.</SPAN>template <SPAN class="operator token">=</SPAN> template<SPAN class="punctuation token">;</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"params"</SPAN><SPAN class="punctuation token">,</SPAN> params<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">//printTask.execute(params).then(printResult);</SPAN>
printTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">execute</SPAN><SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">,</SPAN> printResult<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">// PRINT IMAGE</SPAN>
<SPAN class="comment token">// PRINT RESULT</SPAN>
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">printResult</SPAN><SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
imageUrl <SPAN class="operator token">=</SPAN> evt<SPAN class="punctuation token">.</SPAN>url<SPAN class="punctuation token">;</SPAN>
<SPAN class="token function">setCookie</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'imageUrl'</SPAN><SPAN class="punctuation token">,</SPAN> imageUrl<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>reportType <SPAN class="operator token">==</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">printReport</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>reportType <SPAN class="operator token">==</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"reporttype2 start"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">var</SPAN> printTaskLegend<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> printPars <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
printPars<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>sentScale <SPAN class="operator token">==</SPAN> <SPAN class="number token">1000</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"reporttype2 1000"</SPAN><SPAN class="punctuation token">)</SPAN>
printTaskLegend <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintTask</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
printPars<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>sentScale <SPAN class="operator token">==</SPAN> <SPAN class="number token">2500</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"reporttype2 2500"</SPAN><SPAN class="punctuation token">)</SPAN>
printTaskLegend <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintTask</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
printPars<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">var</SPAN> template <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">PrintTemplate</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
template<SPAN class="punctuation token">.</SPAN>format <SPAN class="operator token">=</SPAN> <SPAN class="string token">'JPG'</SPAN><SPAN class="punctuation token">;</SPAN>
template<SPAN class="punctuation token">.</SPAN>layout <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Print_legend_included'</SPAN><SPAN class="punctuation token">;</SPAN>
template<SPAN class="punctuation token">.</SPAN>preserveScale <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
printPars<SPAN class="punctuation token">.</SPAN>template <SPAN class="operator token">=</SPAN> template<SPAN class="punctuation token">;</SPAN>
printTaskLegend<SPAN class="punctuation token">.</SPAN><SPAN class="token function">execute</SPAN><SPAN class="punctuation token">(</SPAN>printPars<SPAN class="punctuation token">,</SPAN> printImageLegend<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//printTaskLegend.execute(printPars).then(printImageLegend);</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"reporttype2 end"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I am printing out the params with console.log in printImage and according to this, I think it ok?

I tried to use both printTask.execute(params).then(printResult); as well as printTask.execute(params, printResult);
but it just does not go into printResult. Anyone has any idea why?