Copy Attachment with out duplicates

nayeem2
Giga Expert

Hi All,

 

I am trying to copy attachment from task table to request with out duplicates

 

can any one help me

 

thanks in advance

35 REPLIES 35

On sc_task, the field request_item is a reference to the parent (same as the field parent, but parent is on task and request_item is specific to sc_task).   So as long as hr_case is a field on the hr_task table, your code should work... if not, just use parent instead.


I added parent in place of hr_case on lines 7 and 18, but when I do it shows ALL attachments in the related list; lets me open the attachments from the related list though.   There isn't an hr_case field on the hr_task form; just parent.   Any ideas?   I've tried variations of parent vs hr_task by putting one in line 7 and the other in line 18 and vice versa.   No combinations work!  


Oh yeah! You'd need two different Relationships... one for hr_task and one for hr_case.   What you originally had should be working fine if you were on an hr_task looking at related attachments from its parent case or siblings.   However, when you were looking at the hr_case's related attachment it most likely wasn't correct since it was still using the hr_task's defined relationship.   Both would call the same script include, and you've already modified the script include to accept both types (with the if statements).   You just need to have different defined relationships for each of the two tables like how I have one for sc_task, one for sc_req_item, one for sysapproval_approver but they all call the same Script Include and lets its if statements determine which one.


Okay, now I'm totally confused!   I only want my Case form to have a related list that shows the attachments on its child Tasks.



In my relationship, the "Applies to table" should be HR Case, right?




For my script include:


Client callable is unchecked.



function commaSeparatedTaskFamily(fromtable, recid){


  var family = '';


  //first has to find sys_id of target parent


  if (fromtable == 'hr_task'){


  var gr = new GlideRecord('hr_task');


  gr.get(recid);


  family = gr.parent; //gets parent's sys_id since its a reference


  }


  if (fromtable == 'hr_case'){


  family = recid; //itself is the parent


  }


  /* if (fromtable == 'sysapproval_approver'){


  var gr = new GlideRecord('sysapproval_approver');


  gr.get(recid);


  family = gr.sysapproval; //gets the approval_for's sys_id since its a reference


  }*/


  var ngr = new GlideRecord('hr_task');


  ngr.addQuery('parent',family);


  ngr.orderByDesc('number');


  ngr.query();


  while (ngr.next()){


  family += ',';


  family += ngr.sys_id;


  }


  return family;


}


Yes then you only need a single Relationship and it Applies To: hr_case


'hr_case' is the first parameter passed to commaSeparatedTaskFamily


That script include isn't client callable


Lines 4-8 aren't needed since you aren't wanting to display the Related List on the hr_tasks, only the hr_case but if you want to put another related list on them so they can look upward to the parent and over to the siblings you would need another Relationship defined with hr_task as the applies to table and passing that to the script include for those lines to use.


Line 18 needs to be 'hr_case' or 'parent' whichever is a reference field on the hr_tasks (might be hidden and you can see that by checking the XML of the record)



That's all I really see