another blog


About Microsoft Dynamics GP :-)

Saving attachments by using batch file and sanscript code.

Dynamics GP 2013 is providing attachments for several windows. That’s nice to see it. 🙂

I had similar customization for Sales Transaction Entry window for multiple attachments of different type, image file, document file or text file. The attachment icons will be visible if sales order have attachments and will also be available even when orders get transferred into Invoice. For this customization we were saving attachments for sales order from some web pages.

Another window for which we do attachment work is Item Maintenance window. For this purpose we created a setup table for destination path where we save images, user could select image from anywhere and we copy that image to that particular folder so images could be access through other places or web pages.

For this purpose instead of creating any exe or .net project we use sanscript functions and batch programming.Sharing a code here.


On browse button we have this code.


Here we are calling a function where we create folder for respective item on destination path and then create a batch file to copy image file from source to destination path and afterwards delete the batch file.

function returns nothing;
in string i,ip;
out string ap4;

local string drive,p,l_Pathname,l_Returned_String,rString,a,b;
local boolean result,l_File_Error,l_Result,l_result;
local AttachmentPath ap, ap2,ap3;
local integer l_file_ID;

if empty(i) then
abort script;
end if;

if empty(ip) then
abort script;
end if;

‘Setup Key’ of table DestinationAttachmentPath=1;
get table  DestinationAttachmentPath;
if err()=OKAY then
ap=AttachmentPath of table DestinationAttachmentPath; {where we have to save file}
result = Path_DoesExist(AttachmentPath of table DestinationAttachmentPath);
end if;

if result= false then
ask(“Image destination path not setup.”,”OK”,””,””);
abort script;
end if;


{create folder for item number}
result = Path_DoesExist(ap+”\”+i);
if result=false then
ask( “Folder for item “+i+” not created.”,”OK”,””,””);
abort script;
end if;


l_file_ID = TextFile_Open(ap2, 0, 2);
TextFile_WriteLine(l_file_ID,”set ver1=”+DoubleQ+ap3+DoubleQ);
TextFile_WriteLine(l_file_ID,”set ver2=”+DoubleQ+ip+DoubleQ);
{TextFile_WriteLine(l_file_ID,”E:”); {need to set drive here}}
TextFile_WriteLine(l_file_ID,”cd %ver1%”);
TextFile_WriteLine(l_file_ID,”copy %ver2%”);
TextFile_WriteLine(l_file_ID,”del “+DoubleQ+ap2+DoubleQ);
if result=false then
end if;

run application ap2,””;




Filed under: Dexterity Development, Dynamics GP, dynamics-gp, , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: