Auto populate IE form not working

Storm8585

New Member
Joined
Sep 5, 2014
Messages
47
Hi, I have managed to use a version of the code below to log into our client resource management tool and navigate me to another page where I need to add details of an opportunity. However the code keeps erroring at "Set J_id81 = doc.forms(0)". Using Firefox (because its easier) I think I have found the form as J_id81 but I'm not sure. Any help would be much appreciated. Unfortunately you wont be able to visit the page but I have added the source code below also.
Code:
Sub ExAddOppOnly()
    Const cURL = "[URL]https://lustreconsulting.capsulecrm.com/opportunity/add[/URL]" 'Enter the web address here
     
    Const cOppName = "Opp1"
    Const cDesc = "Work"
    Const cValue = "111"
    Const cProb = "0"
    Const cDateClose = "01/12/14"
    Const cFee = "12"
    
    Dim IE As InternetExplorer
    Dim doc As HTMLDocument
    
        
    Dim J_id81 As HTMLFormElement
   
    Dim OppInputBox As HTMLInputElement
    Dim DescInputBox As HTMLInputElement
    Dim ValueInputBox As HTMLInputElement
    Dim ProbInputBox As HTMLInputElement
    Dim DateInputBox As HTMLInputElement
    Dim FeeInputBox As HTMLInputElement
    Dim SaveInButton As HTMLInputButtonElement
    Dim HTMLelement As IHTMLElement
    Dim qt As QueryTable
        
    Set IE = New InternetExplorer
    
    IE.Visible = True
    IE.Navigate cURL
    
    'Wait for initial page to load
    
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
    
     Set J_id81 = doc.forms(0)
        
    Set OppInputBox = J_id81.elements("nameDecorate:name")
    OppInputBox.Value = cOppName
    Set DescInputBox = J_id81.elements("descriptionDecorate:description")
    DescInputBox.Value = cDesc
    Set ValueInputBox = J_id81.elements("amountDecorate:amount")
    ValueInputBox.Value = cValue
    Set ProbInputBox = J_id81.elements("probabilityDecorate:probability")
    ProbInputBox.Value = cProb
     Set DateInputBox = J_id81.elements("expectedCloseDateDecorate:expectedCloseDate")
    DateInputBox.Value = cDateClose
     
     
    Set AllHyperLinks = IE.Document.getElementsByTagName("A")
    For Each hyper_link In AllHyperLinks
    If hyper_link.innertext = "additionalFieldsPanel" Then
    hyper_link.Click
    Exit For
    End If
    Next
    
    Set FeeInputBox = LoginForm.elements("j_id333:0:ungroupedCustomTextDecorate:alphaField")
    FeeInputBox.Value = cFee
    
    'Wait for the new page to load
    
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
    End Sub
[CODE <script src="//cdn.ravenjs.com/1.1.16/jquery,native/raven.min.js"></script><style type="text/css" media="screen">div#navigation li.selected span, div#navigation .menu-open span { text-shadow: none; } div#navigation { background-color: #3D9B46;} div#siteactions-wrapper .menu ul { background-color: #3D9B46; }#nav-search.legacy #globalSearchWrapper { background-color: #3D9B46; }div#navigation .menu ul a:hover, #nav-search.legacy #globalSearchResults td a.active { color: #FFEEA8 !important; background: rgba(255, 238, 168, 0.1) !important; }div#navigation, #nav-search.legacy a, .sitenav a, .siteactions a, div#navigation li.menu-open span { color: #FFEEA8 !important; color: rgba(255, 238, 168, 0.9) !important;} div#navigation li.selected a, #nav-search.legacy a:hover, .sitenav a:hover, #navigation li.menu span:hover { color: #FFEEA8 !important;} .masking div#navigation span.icon { background-color: rgba(255, 238, 168, 0.9) !important;}.masking div#navigation a:hover span.icon, .masking #navigation li.selected span.icon { background-color: #FFEEA8!important;}body.login div#wrapper { background-color: #3D9B46;} </style>

</head>


<body>


<div id="wrapper">


<div id="navigation">

<div id="container">

<div id="content">

<div id="left">

<ul class="sitenav">

<li id="nav-home" class="">

<a href="/" title="Dashboard" class="tipped">

<span class="icon"></span>

</a>

</li>

<li id="nav-parties" class="">

<a href="/parties" title="People & Organisations" class="tipped">

<span class="icon"></span>

</a>

</li>

<li id="nav-calendar" class="">

<a href="/calendar" title="Calendar & Tasks" class="tipped">

<span class="icon"></span>

</a>

</li>

<li id="nav-opportunities" class="">

<a href="/pipeline" title="Sales Pipeline" class="tipped">

<span class="icon"></span>

</a>

</li>

<li id="nav-cases" class="">

<a href="/cases" title="Cases" class="tipped">

<span class="icon"></span>

</a>

</li>

</ul>

</div>

<div id="main">

<ul class="sitenav">

<li class="">

<a href="/party/37112934?t" title="" class="">Rob Rai

</a>

</li>

<li class="">

<a href="/opportunity/2496287?t" title="106 Pavilion Rd" class="tipped">106 Pavilion..

</a>

</li>

<li class="">

<a href="/party/66603293?t" title="" class="">Ian Drummond

</a>

</li>

<li class="">

<a href="/opportunity/2480425?t" title="Kings Rd, Bradford GW" class="tipped">Kings Rd, Bra..

</a>

</li>

<li class="">

<a href="/party/35724605?t" title="" class="">Peter Freeman

</a>

</li>

<li class="">

<a href="/party/62573354?t" title="" class="">Tony Houlding

</a>

</li>

<li class="">

<a href="/opportunity/1941717?t" title="Farnham Road, Slough, SL1" class="tipped">Farnham Road,..

</a>

</li>

<li class="">

<a href="/party/55147041?t" title="" class="">Nicola Duck

</a>

</li>

<li class="">

<a href="/party/36129296?t" title="T Loughman & Co Ltd" class="tipped">T Loughman &..

</a>

</li>

<li class="">

<a href="/party/35724293?t" title="" class="">John Rodgman

</a>

</li>

</ul>

</div>

</div>

</div>


<div id="sidebar">

<div id="siteactions-content">

<div id="nav-search" class="legacy">

<div id="globalSearchWrapper" style="display:none">

<div class="search-results-filters">

<a class="filter-all" data-filter="all">All</a>

<a class="filter-parties" data-filter="parties">Contacts</a>

<a class="filter-opportunities" data-filter="opportunities">Opportunities</a>

<a class="filter-cases" data-filter="cases">Cases</a>

<a class="filter-history" data-filter="history">Notes/Emails</a>

</div>


<div id="globalSearchResults"></div>

</div>

<div id="globalSearchInput">

<img id="search-busy" src="https://d365sd3k9yw37.cloudfront.net/a/1409829884/theme/default/images/busy-small-rotating-arrows.gif" />

<img id="search-close" src="https://d365sd3k9yw37.cloudfront.net/a/1409829884/theme/default/images/search-close.png" style="close" />

<input type="text" size="10" autocomplete="off" placeholder="Search..." />

</div>

</div>

<div id="actions">

<div id="siteactions-wrapper">

<ul class="siteactions">

<li class="menu" id="globalAddMenu"> <span>Add new </span>

<ul id="globalAddMenuContainer">

<li><a href="/parties/add_person">Person</a></li>

<li><a href="/parties/add_organisation">Organisation</a></li>

<li><a href="/opportunity/add">Opportunity</a></li>

<li><a href="/case/add">Case</a></li>

</ul>

</li>

<span class="vr"></span>

<li class="menu" id="globalMoreMenu"> <img width="20" height="20" id="profile-pic" src="https://d365sd3k9yw37.cloudfront.net/a/1409829884/theme/default/images/person_avatar_32.png" /> <span>Matthew Larkin</span>

<ul id="globalMoreMenuContainer">

<li><a href="/preferences">My Preferences</a></li>

<li><a id="getting-started-menu" href="#" title="Getting Started">Getting Started</a></li>

<li><a href="http://support.capsulecrm.com" target="_crmHelp" title="Help" alt="Help">Help</a></li>

<li><a href="/logout">Logout</a></li>

</ul>

</li>

</ul>

</div>

</div>

</div>

</div>

<div class="clearing"></div>

</div>


 

<div id="pageWrapper"><span id="pageHeaderPanel">

<div id="pageHeader">

<div id="pageHeaderWrapper">

<form id="j_id59" name="j_id59" method="post" action="/a/opportunities/new.seam" enctype="application/x-www-form-urlencoded">

<input type="hidden" name="j_id59" value="j_id59" />


<ul class="crumb">

<li>

<script type="text/javascript" language="Javascript">function dpf(f) {var adp = f.adp;if (adp != null) {for (var i = 0;i < adp.length;i++) {f.removeChild(adp);}}};function apf(f, pvp) {var adp = new Array();f.adp = adp;var i = 0;for (k in pvp) {var p = document.createElement("input");p.type = "hidden";p.name = k;p.value = pvp[k];f.appendChild(p);adp[i++] = p;}};function jsfcljs(f, pvp, t) {apf(f, pvp);var ft = f.target;if (t) {f.target = t;}f.submit();f.target = ft;dpf(f);};</script>

<a id="j_id59:pipeline" href="#" *******="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('j_id59'),{'j_id59:pipeline':'j_id59:pipeline','cancelType':'pipeline'},'');}return false">Sales Pipeline</a>

</li>

</ul><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id22" />

</form>


<span class="currentPage">Add Opportunity</span>

</div>

</div></span>


<div id="pageNav">

<div id="pageNavWrapper">

</div>

</div><span id="pageMessagesAndContentPanel">

<div id="pageErrors">

<div id="pageErrorsWrapper"><span id="j_id68">

<form style="display:none">

<input type="hidden" id="hasMessages" value="false" />

</form></span>

</div>

</div><span id="pageContentPanel">

<div id="pageContent">

<div id="pageContentWrapper">

<form id="j_id81" name="j_id81" method="post" action="/a/opportunities/new.seam" class="edit-form" enctype="application/x-www-form-urlencoded">

<input type="hidden" name="j_id81" value="j_id81" />


<div style="display:">

<div class="formsection">

<h3 class="formheading">Details

</h3><span id="partyPanel"><script id="j_id87" type="text/javascript">//<![CDATA[

selectParty=function(partyId){A4J.AJAX.Submit('j_id81',null,{'similarityGroupingId':'j_id87','parameters':{'j_id87':'j_id87','partyId':partyId,'ajaxSingle':'j_id87'} ,'containerId':'j_id86'} )};

//]]></script><script id="j_id89" type="text/javascript">//<![CDATA[

removeContact=function(relPartyId){A4J.AJAX.Submit('j_id81',null,{'similarityGroupingId':'j_id89','parameters':{'ajaxSingle':'j_id89','relPartyId':relPartyId,'j_id89':'j_id89'} ,'containerId':'j_id86'} )};

//]]></script><script id="j_id91" type="text/javascript">//<![CDATA[

addContact=function(relPartyId){A4J.AJAX.Submit('j_id81',null,{'similarityGroupingId':'j_id91','parameters':{'j_id91':'j_id91','ajaxSingle':'j_id91','relPartyId':relPartyId} ,'containerId':'j_id86'} )};

//]]></script><div id="partyDecorate">



<div class="prop"><label>

Opportunity Relates To<span id="partyDecorate:j_id96" class="required">*</span></label>

<span class="field">

<ul class="plain" id="setPartyPanel">

<li>

<label class="compact" for="partySearch">Find a person or organisation by typing their name</label>

<input id="partySearch" name="partySearch" type="text" size="60" />

<span class="text command">or add <a href="#" id="partyDecorate:j_id102" name="partyDecorate:j_id102" *******="A4J.AJAX.Submit('j_id81',event,{'similarityGroupingId':'partyDecorate:j_id102','parameters':{'partyDecorate:j_id102':'partyDecorate:j_id102'} ,'containerId':'j_id86'} );return false;">new person</a> or <a href="#" id="partyDecorate:j_id104" name="partyDecorate:j_id104" *******="A4J.AJAX.Submit('j_id81',event,{'similarityGroupingId':'partyDecorate:j_id104','parameters':{'partyDecorate:j_id104':'partyDecorate:j_id104'} ,'containerId':'j_id86'} );return false;">new organisation</a>

</span>

</li>

</ul>

<script type="text/javascript">

jQuery(function(){


jQuery('#partySearch').partySearch({onPartySelect: function(partyId) {

jQuery('#setPartyPanel li').addClass("busy");

jQuery('#setPartyPanel input').prop('disabled', true);

selectParty(partyId);

jQuery('#nameDecorate\\:name').focus();

}});


jQuery('#partySearch').focus();

});

</script>

</span>

</div></div>


<script type="text/javascript">

jQuery(function(){

jQuery('#contactSearch').partySearch({onPartySelect: function(partyId) {

jQuery('#addContactPanel li').addClass("busy");

jQuery('#addContactPanel input').prop('disabled', true);

addContact(partyId);

jQuery('#nameDecorate\\:name').focus();

}});

jQuery('#contacts li .remove').click(function() {

var $item = jQuery(this).parent('li');

$item.addClass('busy');

removeContact($item.data('partyid'));

});

});

</script></span><div id="nameDecorate">



<div class="prop"><label for="nameDecorate:name" class="">

Opportunity Name<span id="nameDecorate:j_id205" class="required">*</span></label>

<span class="input "><input id="nameDecorate:name" type="text" name="nameDecorate:name" size="60" />

</span>

</div></div><div id="descriptionDecorate">



<div class="prop"><label for="descriptionDecorate:description" class="">

Description</label>

<span class="input "><textarea id="descriptionDecorate:description" name="descriptionDecorate:description" cols="65" rows="3"></textarea>

</span>

</div></div>


<div class="propGroup">

<label>Expected Value</label><div id="amountCurrencyDecorate">



<div class="prop">

<span class="input "><select id="amountCurrencyDecorate:currency" name="amountCurrencyDecorate:currency" size="1"> <option value="AUD">AUD - $</option>

</span>

</div></div><div id="amountDecorate">



<div class="prop">

<span class="input "><input id="amountDecorate:amount" type="text" name="amountDecorate:amount" size="12" />

</span>

</div></div><div id="amountDurationDecorate">



<div class="prop">

<span class="input "><select id="amountDurationDecorate:durationBasis" name="amountDurationDecorate:durationBasis" size="1" onchange="A4J.AJAX.Submit('j_id81',event,{'control':this,'similarityGroupingId':'amountDurationDecorate:j_id236','parameters':{'amountDurationDecorate:j_id236':'amountDurationDecorate:j_id236','ajaxSingle':'amountDurationDecorate:durationBasis'} } )"> <option value="FIXED" selected="selected">fixed</option>

<option value="HOUR">per hour</option>

<option value="DAY">per day</option>

<option value="WEEK">per week</option>

<option value="MONTH">per month</option>

<option value="QUARTER">per quarter</option>

<option value="YEAR">per year</option>

</select>

</span>

</div></div><span id="durationBasisPanel"></span>

</div>


<div class="propGroup"><div id="stageDecorate">



<div class="prop"><label for="stageDecorate:j_id256" class="">

Milestone<span id="stageDecorate:j_id252" class="required">*</span></label>

<span class="input "><select name="stageDecorate:j_id256" size="1" onchange="A4J.AJAX.Submit('j_id81',event,{'control':this,'similarityGroupingId':'stageDecorate:j_id257','parameters':{'ajaxSingle':'stageDecorate:j_id256','stageDecorate:j_id257':'stageDecorate:j_id257'} } )"> <option value="org.jboss.seam.ui.NoSelectionConverter.noSelectionValue">select...</option>

<option value="0">Discussion</option>

<option value="1">Lost</option>

<option value="2">On hold</option>

<option value="3">Pending</option>

<option value="4">Won</option>

</select>

</span>

</div></div><span id="probabilityPanel"><div id="probabilityDecorate">



<div class="prop"><label for="probabilityDecorate:probability" class="">

Probability of Winning (%)</label>

<span class="input "><input id="probabilityDecorate:probability" type="text" name="probabilityDecorate:probability" size="5" />

</span>

</div></div></span>

</div><div id="expectedCloseDateDecorate">



<div class="prop"><label for="expectedCloseDateDecorate:j_id280" class="">

Expected Close Date</label>

<span class="input "><input type="text" name="expectedCloseDateDecorate:j_id280" class="datepicker" />

</span>

</div></div><span id="actualCloseDatePanel"></span><div id="caseTypeDecorate">



<div class="prop"><label for="caseTypeDecorate:j_id302" class="">

Track</label>

<span class="input "><select name="caseTypeDecorate:j_id302" size="1"> <option value="org.jboss.seam.ui.NoSelectionConverter.noSelectionValue">select...</option>

<option value="5">Proposal Follow-up</option>

</select>

</span>

<p class="hint"></p>

</div></div><div id="ownerDecorate">



<div class="prop"><label for="ownerDecorate:eek:wner" class="">

Owner</label>

<span class="input "><select id="ownerDecorate:eek:wner" name="ownerDecorate:eek:wner" size="1"> <option value="6">Me</option>



</select>

</span>

</div></div>


<div class="clear"></div><span id="additionalFieldsPanel">

<div class="prop"><a class="action" href="#" id="j_id324" name="j_id324" *******="A4J.AJAX.Submit('j_id81',event,{'similarityGroupingId':'j_id324','parameters':{'j_id324':'j_id324','ajaxSingle':'j_id324'} } );return false;">

enter additional fields (Fee, Note)</a>

</div></span>

<div class="clear"></div>

</div><span id="dataTagFields"></span>


 

<ul class="formActions">

<li><input id="save" type="submit" name="save" value="Save" *******="style.display='none';jQuery('#oppSaveButtonSwap').show();" class="btn singlesubmit" />

</li>

<li><a id="cancel" href="#" *******="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('j_id81'),{'cancel':'cancel'},'');}return false">Cancel</a></li>


</ul>

</div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id22" />

</form>

</div>

</div></span></span>


<div class="clear"></div>

</div>


<div id="footer"></div>

</div>


<script type="text/javascript">

app.Theme.images = "/theme/default/images";

app.Theme.mediumIcons = "/theme/default/images/22x22";

app.Assets.setPath("https://d365sd3k9yw37.cloudfront.net/a/1409829884");


app.timezone = "Europe/London";

app.timezoneOffset = 60;

app.locale = "en_GB";

app.firstDayOfWeek = 1;

app.dateFormat = "dd/mm/yy";


$(function(){

app.postPageLoad();

app.postContentRender();

});

</script>
][/CODE]
 
Last edited:

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Watch MrExcel Video

Forum statistics

Threads
1,122,548
Messages
5,596,787
Members
414,102
Latest member
8885001133

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top