roelmagpoc Posted February 14, 2014 Report Share Posted February 14, 2014 I need to redirect using a virtual field depending on a datafield value. The virtual field will be assigned the link depending on the WorkOrderDetail. The redirect will happen afer submitting the form. I am also passing an autonumber field called the WorkOrderId. I’m able to pass the autonumber correctly when redirecting, however, my criteria (the if-condition) is not working properly. Here’s my current script which I placed in the footer - it always goes to the “else†part even when it should satisfy the if criteria.(I plan to add more criteria but need to make the script work first.) <script type="text/javascript"> { if ("[@field:WorkOrderDetail]" == "M1 TDM"){document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b9443000bc1de4154c364d53a0b5";} else{document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b9443000fa23580f2eda4a41bb40";} }</script> Hope you guys can help. Quote Link to comment Share on other sites More sharing options...
luizcruz Posted February 14, 2014 Report Share Posted February 14, 2014 Hi Heisenberg! I'm a Newbie too, but I would like to help you, Are you receiving the field [@field:WorkOrderDetail] as parameter from another DataPage or it´s part of the same DataPage? Your dataPage is a submission form? Regards! Luiz Quote Link to comment Share on other sites More sharing options...
Jan Posted February 14, 2014 Report Share Posted February 14, 2014 Hello! As far as I know, javascript doesn't work with parameters like [@field:WorkOrderDetail] It's better to use code like var variable = document.getElementById("ID").value; and then work with this variable. ID for Submission forms is: "InsertRecordFieldName", e.g., InsertRecordWorkOrderDetail And for Update Form is: "EditRecordFieldName", e.g., EditRecordWorkOrderDetail Quote Link to comment Share on other sites More sharing options...
roelmagpoc Posted February 14, 2014 Author Report Share Posted February 14, 2014 Luis - [@fieldWorkOrderDetail] is a dropdown datafield in my submission form. (The codes I'm using I based from your other posts.) Jan - I tried defining the variables but they still don't work. Here was my original script (I actually just copy codes from this forum; I'm really not a JS programmer). I tried using both getElementById and getElementsByName. When I include the prefix "InsertRecord", I get a "404-File not found" error. <script type="text/javascript"> { var x = document.getElementsByName("WorkOrderType"); var y = document.getElementsByName("WorkOrderDetail"); if (y == 'M1 TDM') {document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b9443000bc1de4154c364d53a0b5";} else if (y == ‘M1 Fiber’) {document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b94430008aaa7fbc77eb48df83f8";} else {document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b9443000fa23580f2eda4a41bb40";} } </script> Quote Link to comment Share on other sites More sharing options...
luizcruz Posted February 15, 2014 Report Share Posted February 15, 2014 Hello Heisenberg! Before run the below script go to "Web Form Wizard - Destinations and Triggers to set the destination options: Destination after record submit: Go to a new page Page URL: [@Virtual1] =>> In your last script you forgot the last command "document.getElementById("caspioform").onsubmit=myFunction;" Try this script! <script> function myFunction() { var y = document.getElementsByName("InsertRecordWorkOrderDetail")[0].value; if(y == "M1 TDM"){ document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b9443000bc1de4154c364d53a0b5";} else if(y == "M1 Fiber"){ document.getElementById("cbParamVirtual1").value = "http://b6.caspio.com/dp.asp?AppKey=b94430008aaa7fbc77eb48df83f8";} } document.getElementById("caspioform").onsubmit=myFunction; </script> I hope it works! Regards! Luiz Quote Link to comment Share on other sites More sharing options...
roelmagpoc Posted February 19, 2014 Author Report Share Posted February 19, 2014 Thanks Luis & Jan! I have a working code now. Major lesson learned: define the function and run it upon submit. I did not do this the first time so my codes were not working. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.