Autocreation of Task from demands based on conditions.

Shyna1
Tera Contributor
  • Whenever any  new Demand is created with Company as  TECHS, new Demand Task will be  automatically created.

The number of demand tasks created will depend on the number of values in the 'Business application' field in the demand record . if there are two values in the 'Business application' field then there will be two tasks created one for each business application.

Note-Business application is a List collector 

The field mapping would be :

Priority- 2

shortdescription- task created for $business application

 

Thanks in advance!

 

 

1 ACCEPTED SOLUTION

For your second part of query, for setting the priority as None but it's not happening because Priority is a Field on Task Table and has a Default value being set in it as shown below which is 4 i.e. Low and hence when ever a task is getting created it is setting it as Low:

find_real_file.png  Now in order to override this , Right click on Priority field and select Configure Dictionary and then scroll down to Dictionary Override as shown below:

Click on New Button:

find_real_file.png

Select Table as Demand Task and then select the check box as Override Default Value and leave it blank value in below field of Default value:

find_real_file.png

Now when your Demand Task will be created the priority value will be empty as you want as shown below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

HI Shyna,

 

The below thread will help you:

https://community.servicenow.com/community?id=community_question&sys_id=a7cf31861b2bb810fc3233bc1d4bcbdc

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

shloke04
Kilo Patron

Hi,

Please write a After Insert Business Rule on Demand table and use the script as below:

Condition of BR: 

Company is TECHS AND business Application is Not Empty

 

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var getCurrentBusinessApplications = current.business_applications;
	var splitApplications = getCurrentBusinessApplications.split(',');
	for(var i=0;i<splitApplications.length;i++){
		createDemandtask();
	}
	
	function createDemandtask(){
		var gr = new GlideRecord('dmn_demand_task');
		gr.initialize();
		gr.parent = current.sys_id;
		gr.FIELDNAME = current.FIELDNAME; // Replace "FIELDNAME" in case you want to copy field values as well
		gr.insert();
	}

})(current, previous);

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

For example have tested the above code and it works correctly. I have two Business Applications on my Demand form and hence two Demand Task got created as shown below.

If you want to copy field values from Demand to Demand task while creating task you can replace those field in place of Field Name in script above.

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Shyna1
Tera Contributor

Hi Shloke,

 

Thank you so much for the script.

One more challenge i am facing - I want the short description of the demand task created for each business application to have the Business application populated in the short description.Like 

If there are two application like attendance payroll management and event management , the short description of the two tasks created should have following business application name populated.one task with one business app name populated.

One more thing if i were to set the priority value to None for the demand task , how should i do it

i am setting urgency and impact value to null still the priority value is taking as priority 5