I have used Server side javascript with a mix of ampscript to handle the error but the issue is even for the correct syntax the page is being redirected to error. When i remove the SSJS exception handle code from the page then code works correctly. Below is my code.
<script runat="server" type="text/javascript">
Platform.Load("core","1");
try {
</script>
%%[
/*fetch the id form URL*/
SET @cid = Queryparameter("cid")
/*check if the id is empty*/
if empty(@cid) then
redirect(CloudPagesURL(20)) /*redirects to error page*/
endif
/*personal information*/
SET @firstName = RequestParameter("First_Name__c")
SET @lastName = RequestParameter("Last_Name__c")
SET @jobRole = RequestParameter("Job__c")
SET @country = RequestParameter("country")
SET @state = RequestParameter("state")
SET @city = RequestParameter("City__c")
SET @email = RequestParameter("Email__c")
SET @mobilePhone = RequestParameter("Phone__c")
SET @training = "True"/* change the organization to training and assign the values*/
/*Your interest*/
SET @Accessibility = RequestParameter("int1")
if empty(@Accessibility) then
SET @Accessibility = "False"
endif
SET @Agile = RequestParameter("int2")
if empty(@Agile) then
SET @Agile = "False"
endif
SET @Automation = RequestParameter("int3")
if empty(@Automation) then
SET @Automation = "False"
endif
SET @BusinessAnalysis = RequestParameter("int4")
if empty(@BusinessAnalysis) then
SET @BusinessAnalysis = "False"
endif
SET @Cloud = RequestParameter("int5")
if empty(@Cloud) then
SET @Cloud = "False"
endif
SET @CrowdTesting = RequestParameter("int6")
if empty(@CrowdTesting) then
SET @CrowdTesting = "False"
endif
SET @DevOps = RequestParameter("int7")
if empty(@DevOps) then
SET @DevOps = "False"
endif
SET @Digital = RequestParameter("int8")
if empty(@Digital) then
SET @Digital = "False"
endif
SET @Environments = RequestParameter("int9")
if empty(@Environments) then
SET @Environments = "False"
endif
SET @IoTandWearable = RequestParameter("int10")
if empty(@IoTandWearable) then
SET @IoTandWearable = "False"
endif
SET @ManagedServices = RequestParameter("int11")
if empty(@ManagedServices) then
SET @ManagedServices = "False"
endif
SET @ManualTesting = RequestParameter("int12")
if empty(@ManualTesting) then
SET @ManualTesting = "False"
endif
SET @Mobile = RequestParameter("int13")
if empty(@Mobile) then
SET @Mobile = "False"
endif
SET @Monitoring = RequestParameter("int14")
if empty(@Monitoring) then
SET @Monitoring = "False"
endif
SET @Offshoring = RequestParameter("int15")
if empty(@Offshoring) then
SET @Offshoring = "False"
endif
SET @OperationalReadiness = RequestParameter("int16")
if empty(@OperationalReadiness) then
SET @OperationalReadiness = "False"
endif
SET @Performance = RequestParameter("int17")
if empty(@Performance) then
SET @Performance = "False"
endif
SET @ProcessOptimisation = RequestParameter("int18")
if empty(@ProcessOptimisation) then
SET @ProcessOptimisation = "False"
endif
SET @ProjectManagement = RequestParameter("int19")
if empty(@ProjectManagement) then
SET @ProjectManagement = "False"
endif
SET @Security = RequestParameter("int20")
if empty(@Security) then
SET @Security = "False"
endif
SET @TestMgmtandStrategy = RequestParameter("int21")
if empty(@TestMgmtandStrategy) then
SET @TestMgmtandStrategy = "False"
endif
SET @Virtualisation = RequestParameter("int22")
if empty(@Virtualisation) then
SET @Virtualisation = "False"
endif
/*Your communication preference*/
SET @Articles_Surveys_Statistics = RequestParameter("arsust1")
if empty(@Articles_Surveys_Statistics) then
SET @Articles_Surveys_Statistics = "False"
endif
SET @ProductReleases_InfoandSpecials = RequestParameter("pris1")
if empty(@ProductReleases_InfoandSpecials) then
SET @ProductReleases_InfoandSpecials = "False"
endif
SET @WebinarandEventInvitations = RequestParameter("wei1")
if empty(@WebinarandEventInvitations) then
SET @WebinarandEventInvitations = "False"
endif
/*check if the user exist or not*/
SET @lookupContact = RetrieveSalesforceObjects("Contact","Id", "Id","=", @cid)
if rowcount(@lookupContact) != 0 then
SET @updateContact = UpdateSingleSalesforceObject("Contact", @cid, "FirstName", @firstName, "LastName", @lastName, "Job_Role__c", @jobRole, "Email", @email, "MailingCountry", @country, "MailingState", @state, "MailingCity", @city, "MobilePhone", @mobilePhone, "Accessibility__c",@Accessibility,"Agile__c",@Agile,"Automation__c",@Automation,"Business_Analysis__c",@BusinessAnalysis,"Cloud__c",@Cloud,"Crowd_Testing__c",@CrowdTesting,"DevOps__c",@DevOps,"Digital__c",@Digital,"Environments__c",@Environments,"IoT_Wearables__c",@IoTandWearable,"Managed_Services__c",@ManagedServices,"Manual_Testing__c",@ManualTesting,"Mobile__c",@mobilePhone,"Monitoring__c",@Monitoring,"Off_Shoring__c",@Offshoring,"Operational_Readiness__c",@OperationalReadiness,"Performance__c",@Performance,"Process_Optimisation__c",@ProcessOptimisation, "Project_Management__c",@ProjectManagement,"Security__c",@Security,"Test_Mgmt_Strategy__c",@TestMgmtandStrategy,"Virtualisation__c",@Virtualisation,"Articles_Surveys_Statistics__c",@Articles_Surveys_Statistics,"Product_Info_Specials__c",@ProductReleases_InfoandSpecials,"Webinar_Event_Invitations__c",@WebinarandEventInvitations, "Training__C", @training )
else
redirect(CloudPagesURL(20)) /*redirects to error page*/
endif
if @updateContact == 1 then
redirect(CloudPagesURL(21)) /*redirects to thank you page*/
else
redirect(CloudPagesURL(20)) /*redirects to error page*/
endif
]%%
<script type="text/javascript" runat="server">
}
catch (e) {
</script>
%%[redirect(CloudPagesURL(20)]%%
<script type="text/javascript" runat="server">
}
</script>