Import Set from UI Action

Blair5
Tera Guru

I have a requirement to allow the help desk administrator to upload a spreadsheet and import it into a specific table using a UI action. Basically, they click on a button called "Batch Add" and an attachment pop up appears, when they click attach and close, the file is uploaded. Has anyone else done something similar with a UI action?

10 REPLIES 10

VamsiKommireddi
Kilo Contributor

Hi Aron,

As one data source cant have 2 attachments as the source,Only one attachment can be processed at a time.
So,I have added delay the 2nd user request when one user request is in progress.If Service Desk user is not loading more than 500 records of data then it will working fine as it takes only 4 or 5 seconds to process.

Regards,
Vamsi Kommireddi,
Certified System Administrator.


nj70
Kilo Contributor

Hi Blari,



Have you implemented this solution?..


I am trying to do but I got stuck at creation of   the Ui action.


Can you please share the code(UI action) if you have implemented it( I know this is a long back post but just a try).



Thanks..


This is what we did:



if (!current.hasAttachments()) {


gs.addErrorMessage('No attachments found.');


action.setRedirectURL(current);


//current.setAbortAction(true);


} else {



var batch_add = gs.getProperty('batch.add.data.source.id');



// Delete all attachments from data source


deleteAllAttachments("sys_data_source", batch_add);



// Delete all attachments except the last uploaded one from the flash message record


deleteAllAttachmentsExceptLast("u_flash_message", current.sys_id);



//Check to see if the Package call alternate is available and use that if possible. Else, use the package call.


if (typeof GlideSysAttachment != 'undefined'){


GlideSysAttachment.copy("u_flash_message", current.sys_id, "sys_data_source", batch_add);


}else{


GlideSysAttachment.copy("u_flash_message", current.sys_id, "sys_data_source", batch_add);


}



//Execute a scheduled script job


var rec = new GlideRecord('scheduled_import_set');


rec.get('name', 'Import Flash Messages');


if (typeof SncTriggerSynchronizer != 'undefined'){


SncTriggerSynchronizer.executeNow(rec);


action.setRedirectURL(current);


//action.setReturnURL(current);


gs.sleep(2000);


gs.eventQueue('bulk_load_complete', current, gs.getUserID(), gs.getUserName());


gs.addInfoMessage("All users contained in the spreadsheet have been added to the appropriate flash message.");


}else{


SncTriggerSynchronizer.executeNow(rec);


//action.setRedirectURL(current);


gs.sleep(2000);


gs.eventQueue('bulk_load_complete', current, gs.getUserID(), gs.getUserName());


gs.addInfoMessage("All users contained in the spreadsheet have been added to the appropriate flash message.");


action.setReturnURL(current);


}


}




function deleteAllAttachmentsExceptLast(table_name, sys_id){


var gr = new GlideRecord("sys_attachment");


gr.addQuery("table_name", table_name);


gr.addQuery("table_sys_id", sys_id);


gr.orderBy("sys_created_on");


gr.query();



var N = gr.getRowCount();


var counter = 0;



while (gr.next()){


if( counter == N - 1 )


break;


gr.deleteRecord();


counter++;


}


}




function deleteAllAttachments(table_name, sys_id){


var gr = new GlideRecord("sys_attachment");


gr.addQuery("table_name", table_name);


gr.addQuery("table_sys_id", sys_id);


gr.deleteMultiple();


}


kgulve117
Kilo Contributor

Breinhart,

We have the similar requirement to allow the help desk administrator to upload a spreadsheet and import it into a specific table using a UI action.

 

How attachment pop up appears when user click on a button. Can you please share the code if you have implemented it, Also what would be the best way to implement this?

 

 

 

Swati16
Tera Contributor

Hello @Blair Reinhart 

 

We have the similar requirement to allow the help desk administrator to upload a spreadsheet and import it into a specific table using a UI action.

 

How attachment pop up appears when user click on a button. Can you please share the code if you have implemented it, Also what would be the best way to implement this?