HTML Field value displaying multiple times

pk16514
Tera Contributor

There is a catalog Item say 'XYZ'. It has a attachment variable field named as  "Upload Picture".

Upload Picture is a variable inside a Variable Set. There are two more variable whose type is HTML and their names are

Photo(image) and Preview(preview).

Issue Description-

When we add an image in attachment field. The image is being displayed under Photo and Preview as below-

pk16514_0-1729539971489.png

When we remove the attachment and upload the same attachment again then it shows the Same image under photo 3 times and under preview 3 times.

On Repeating the same process again, this time it shows 9 times, 27 times so on.

1, 3, 9, 27,......the pattern is like this.

The On Change Client script on the variable "upload_photo" which is populating the HTML fields is as below-

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

	g_form.addInfoMessage("SysId " + newValue);

    if (newValue != oldValue || newValue == '') {
		g_form.addInfoMessage("Test1");
		
        g_form.setReadOnly('preview', false);
        g_form.clearValue('preview');
        g_form.setVisible('preview', false);
        g_form.setReadOnly('image', false);
        g_form.clearValue('image');
        g_form.setVisible('image', false);
		return;
    }
    //Type appropriate comment here, and begin script below
    var ajax = new GlideAjax('badgeAjaxUtils');
    ajax.addParam('sysparm_name', 'validatePictureSize');
    ajax.addParam('sysparm_attachment', newValue);
    ajax.getXML(validResponse);

    function validResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        var image1 = "<tr><td width='250px'> <img src='/sys_attachment.do?sys_id=" + newValue + "' style='width:250px; height:auto;'> </td></tr>";
        if (answer == 'false') {
			g_form.addInfoMessage("Test2");
            g_form.clearValue('image');
            g_form.setVisible('image', false);
			g_form.clearValue('preview');
            g_form.setVisible('preview', false);

            g_form.setValue('preview', image1);
            g_form.setVisible('preview', true);
            g_form.setReadOnly('preview', true);
            g_form.removeDecoration('preview');

            g_form.clearValue('upload_photo');
            g_form.setMandatory('upload_photo', true);
            g_form.addErrorMessage("Die maximal zulässige Bildgröße wurde überschritten. / The maximum allowed image size has been exceeded.");
        }
        if (answer == 'true') {
			g_form.addInfoMessage("Test3");
            g_form.clearValue('preview');
            g_form.setVisible('preview', false);
            g_form.clearValue('image');
            g_form.setVisible('image', false);

            g_form.setValue('preview', image1);
            g_form.setVisible('preview', true);
            g_form.setReadOnly('preview', true);
            g_form.removeDecoration('preview');

            g_form.setValue('image', image1);
            g_form.setVisible('image', true);
            g_form.setReadOnly('image', true);
            g_form.removeDecoration('image');
        }
		return;

    }
}

 

The script include "badgeAjaxUtils" function "validatePictureSize" is as below-

validatePictureSize : function() {
		var debug = (gs.getProperty('kms.badge.debug', false).toString() == "true");
		var attachment_sys_id = this.getParameter('sysparm_attachment');
		var grAttachment = new GlideRecord('sys_attachment');
		grAttachment.get(attachment_sys_id);
		var size = grAttachment.size_bytes;
		if (debug) {
            gs.info("Method: validatePictureSize attachment_sys_id: " + attachment_sys_id);
            gs.info("Method: validatePictureSize size: "+size);
            gs.info("Method: validatePictureSize Table sys id: " + grAttachment.table_sys_id);
        }		
		if(grAttachment.size_bytes > 500000){ // 500kb			
			//grAttachment.deleteRecord();
			return false;
		}else return true;
	},


When I remove the two setReadOnly code line from the client script if condition (newValue != oldValue || newValue == ""), it is working fine. But I don't understand why. Please help me to fix this issue and explain why it is happening.

Thanks,
Prabhakar

 

0 REPLIES 0