How to copy attachments from defect (OOB UI Action)

sinu2
Tera Expert

Hi ,

 

I need to Modify out of the box UI action (create_story). Need to copy attachments from demand to story while creating story from demand. Below is the existing code.

 

function openFormDialog(){
	var sysId;
	if (typeof rowSysId == 'undefined')
		sysId = gel('sys_uniqueValue').value;
	else
		sysId = rowSysId;
	var gModalForm = new GlideModalForm(getMessage('Create Story'), 'rm_story');
	gModalForm.setPreference('sysparm_view',  'scrum');
	gModalForm.setPreference('sysparm_query', 'short_description=' + g_form.getValue('short_description') +
	'^description=' + g_form.getValue('description') +
	'^assigned_to=' + g_form.getValue('assigned_to') +
	'^cmdb_ci=' + g_form.getValue("cmdb_ci") +
	'^classification=Defect' +
	'^type=Development' +
	'^defect=' + sysId);
	gModalForm.render();
	gModalForm.setCompletionCallback(function(actionVerb, storySysId){
		var ga = new GlideAjax('AgileAjaxProcessor');
		ga.addParam('sysparm_name', 'updateStoryDefect');
 		ga.addParam('sysparm_defect_sys_id', sysId);
 		ga.addParam('sysparm_story_sys_id', storySysId);
		ga.getXML(function() {
			if (typeof GlideList2 !== 'undefined' && GlideList2.get("rm_defect.rm_story.defect")) {
				GlideList2.get("rm_defect.rm_story.defect").refresh();
			}
		});
	});
}

 

1 ACCEPTED SOLUTION

Ops sorry..we have to write that logic in script include..for the same function..also put some logs for debugging purpose ..

 

So in function copyAtt() put alert for parameters then-> use GlideAjax and in script include put some logs there and let me know where is the exact issue

View solution in original post

10 REPLIES 10

even 1st log is also not coming before or after function 

 

 

function openFormDialog() {	
    var sysId;
    if (typeof rowSysId == 'undefined')
        sysId = gel('sys_uniqueValue').value;
    else
        sysId = rowSysId;
    var gModalForm = new GlideModalForm(getMessage('Create Story'), 'rm_story');
    gModalForm.setPreference('sysparm_view', 'scrum');
    gModalForm.setPreference('sysparm_query', 'short_description=' + g_form.getValue('short_description') +
        '^description=' + g_form.getValue('description') +
        '^assigned_to=' + g_form.getValue('assigned_to') +
        '^cmdb_ci=' + g_form.getValue("cmdb_ci") +
        '^classification=Defect' +
        '^type=Development' +
        '^defect=' + sysId);
    gModalForm.render();
    gModalForm.setCompletionCallback(function(actionVerb, storySysId) {
        var ga = new GlideAjax('AgileAjaxProcessor');
        ga.addParam('sysparm_name', 'updateStoryDefect');
        ga.addParam('sysparm_defect_sys_id', sysId);
        ga.addParam('sysparm_story_sys_id', storySysId);
        ga.getXML(function() {
            if (typeof GlideList2 !== 'undefined' && GlideList2.get("rm_defect.rm_story.defect")) {
                GlideList2.get("rm_defect.rm_story.defect").refresh();
				copyAtt(sysId, storySysId);

            }
        });
    });
}
gs.log('ui action 31 line');
function copyAtt(sysId, storySysId) {

gs.log('ui action 34 line');
    var grStory = new GlideRecord('rm_story');
    if (grStory.get(storySysId))
	gs.log('ui action 37 line'+ grStory.sys_id);
    {
        var grAtt = new GlideRecord('sys_attachment');
        grAtt.addQuery('table_sys_id', sysId);
        grAtt.addQuery('table_name', 'rm_defect');
        grAtt.query();
        while (grAtt.next()) {

            var attachment = new GlideSysAttachment();
            var copiedAttachments = attachment.copy('rm_defect', sysId, 'rm_story', grStory.sys_id);
        }
    }
}