<code> <span class="token keyword">var</span> startDate <span class="token operator">=</span> current<span class="token punctuation">.</span>start_date<span class="token punctuation">.</span><span class="token function">getGlideObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">var</span> endDate <span class="token operator">=</span> current<span class="token punctuation">.</span>end_date<span class="token punctuation">.</span><span class="token function">getGlideObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> current<span class="token punctuation">.</span>calendar_duration <span class="token operator">=</span> gs<span class="token punctuation">.</span><span class="token function">dateDiff</span><span class="token punctuation">(</span>startDate<span class="token punctuation">.</span><span class="token function">getDisplayValueInternal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> endDate<span class="token punctuation">.</span><span class="token function">getDisplayValueInternal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code>
How to populate duration filed on change request based on Start date and End date ServiceNow
Working Code Asked question August 19, 2024