PDA

View Full Version : Variable for date and time in IA 2011



Nehaggn
07-21-2011, 04:40 AM
Hi,

I am using InstallAnywhere. I need to know that is there any variable which we can use to show date and time. For ex: in Installshield if we were using $J(date) then how can we achieve this in IA 2011.


Thanks in advance.

pv7721
07-21-2011, 05:00 AM
Where exactly do you want to show the date? You mean the build date?

Nehaggn
07-22-2011, 05:48 AM
Actually i m using an ASCII file to modify text file where it will search for a string and then replace it with DATE.
U can say search and replace strings in ASCII file.
So how can we replace a string with current date and time??

pv7721
07-22-2011, 07:16 AM
Sorry, I'm afraid I still don't understand the context. Is it possible for you to post your project?

Masudkhan
07-25-2011, 07:19 AM
Hi,

I do not think IA provides any variable that stores the system date.

But you can create a custom action where you retrieve system date/time using java and set an IA variable (say $MY_DATE$).

First add an execute custom action, where you will select your custom code jar.
Next you can add a "Modify Text file" action.
In the file you will be specifying the variable $MY_DATE$ in the place where you want the system date.

Now after execution of the action, the $MY_DATE$ in the file will be replaced with the value of that variable at run time.

Nehaggn
08-02-2011, 06:08 AM
Hi,

Thanks for the approach.
I hav created a custom action with date and time variables and also created IA variable for the same.
But how can i utilize the value of these variables(date and time) in IA 2011.
I mean how to set the IA variable to use the output of my java custom code.


Thanks.

Masudkhan
08-03-2011, 04:09 AM
Hi,

First your custom code must update the IA variable(name say $SYSTEM_DATE$) that you have created.
(You can use the attached SystemDate.jar for that purpose.)

Next add an execute custom code action, where you will select your custom code jar i.e SystemDate.jar.

Now you have to add a "Modify Text file" action.

In the file you will be specifying the variable $SYSTEM_DATE$ in the place where you want the system date.

Now after execution of the action, the $SYSTEM_DATE$ in the file will be replaced with the value of that variable at run time.


--
Regards,
Masud

Masudkhan
08-03-2011, 04:20 AM
Here is custom code sorce.
If you want a different date format or change the IA variale name, then you can modify the code accordingly. Then you have to comiple the code and build the jar again.

package com.zerog.ia.customcode.action;

import java.io.*;
import java.util.*;

import com.zerog.ia.api.pub.*;

public class SystemDate extends CustomCodeAction
{
public String getInstallStatusMessage()
{
return "Reading System Date";
}

public String getUninstallStatusMessage()
{
return "";
}

public void install(InstallerProxy ip) throws InstallException
{
String substituteVariables = ip.substitute("$SUBSTITUTE_VARIABLES$");
String overrideVariables = ip.substitute("$OVERRIDE_EXISTING_VARIABLES$");


if(overrideVariables.equals(""))
{
overrideVariables = "true";
}
if(substituteVariables.equals(""))
{
substituteVariables = "true";
}


try
{
Date thedate = new Date();
//Do this if the user wants to substitute IA variables
if(substituteVariables.equalsIgnoreCase("true"))
{
// If the user wants to override variables, just set the value
if(overrideVariables.equalsIgnoreCase("true"))
{
ip.setVariable("$SYSTEM_DATE$",ip.substitute(thedate.toString()));
}
// If the user does not want to override values, but the variable does not exist, set it
else if(overrideVariables.equalsIgnoreCase("false") && ip.substitute("$SYSTEM_DATE$").equals(""))
{
ip.setVariable("$SYSTEM_DATE$",ip.substitute(thedate.toString()));
}
}
//Do this if the user does not want to substitute IA variables
else
{
// If the user wants to override variables, just set the value
if(overrideVariables.equalsIgnoreCase("true"))
{
ip.setVariable("$SYSTEM_DATE$",thedate.toString());
}
// If the user wants to override variables, just set the value
else if(overrideVariables.equalsIgnoreCase("false") && ip.substitute("$SYSTEM_DATE$").equals(""))
{
ip.setVariable("$SYSTEM_DATE$", thedate.toString());
}
}

System.err.println("Setting $SYSTEM_DATE$ to " + thedate);
}
catch (Exception e)
{
System.out.println("Exception caught =" + e.getMessage());
throw new NonfatalInstallException ("Exception");
}
}

public void uninstall(UninstallerProxy up) throws InstallException
{

}

}

markfly
08-15-2011, 05:38 AM
I suspect that there is something in the java code in my project that could be the cause of this. Of course, it is a massive code and may take a while to track it down.

Masudkhan
08-16-2011, 12:43 AM
Reply to Markfly's following post

Q: I mean how to set the IA variable to use the output of my java custom code.

A: The custom code i posted earlier takes care of setting the IA variable named $SYSTEM_DATE$.
So after execution of this custom code, you can directly use $SYSTEM_DATE$ variable that will contain the system date/time (value would be the date/time at which the custom code was executed).