You need to sign in to do that
Don't have an account?
Dale Worthington
Checking a field is populated in a JS Button
Hi here
I use JS to make an record in an object called 'Incident2op__c' and also update the notes on the incident (TicketMGNT__IncidentHistory__c).
Once an Incident2op__c record is made a process flow takes it and converts it to an opportunity. The problem is that the field 'TicketMGNT__Incident__c.Billing_Work_Type__c' becomes the Incident2op__c's name, and that is then maps to the opporitnity name. So if the Incident2Op name is blank i get a FlowApplication error to my mailbox. The user is unaware and thinks it all went well.
I tried to modify my button like this:
but now nothing happens. The oringal button looked like this:
you can see the changes i made on line 25 where i defined billingwork type
line 27 i made an if statement
line 69/72 i deal with the if statement.
I hope someone can give me a good lesson on how this should work
Cheers
Dale
I use JS to make an record in an object called 'Incident2op__c' and also update the notes on the incident (TicketMGNT__IncidentHistory__c).
Once an Incident2op__c record is made a process flow takes it and converts it to an opportunity. The problem is that the field 'TicketMGNT__Incident__c.Billing_Work_Type__c' becomes the Incident2op__c's name, and that is then maps to the opporitnity name. So if the Incident2Op name is blank i get a FlowApplication error to my mailbox. The user is unaware and thinks it all went well.
I tried to modify my button like this:
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')} getDate = function(dateObj){ var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay(); var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth(); return dateObj.getFullYear()+'-'+month+'-'+day; } var thedatetime = function xsdDateTime(date) { function pad(n) { var s = n.toString(); return s.length < 2 ? '0'+s : s; }; var yyyy = date.getFullYear(); var mm1 = pad(date.getMonth()+1); var dd = pad(date.getDate()); var hh = pad(date.getHours()); var mm2 = pad(date.getMinutes()); var ss = pad(date.getSeconds()); return yyyy +'-' +mm1 +'-' +dd +'T' +hh +':' +mm2 +':' +ss; } var billingworktype = "{!TicketMGNT__Incident__c.Billing_Work_Type__c}" if(billingworktype != "" && text != null) { var ito = new sforce.SObject('Incident2Op__c'); ito.Name = '{!TicketMGNT__Incident__c.Name}'; ito.OwnerId = '{!User.Id}'; ito.Note1__c = "{!TicketMGNT__Incident__c.Invoice_Note__c}" ; ito.WorkType__c = '{!TicketMGNT__Incident__c.Billing_Work_Type__c}' ; ito.Category__c = "{!TicketMGNT__Incident__c.TicketMGNT__FKCategory__c }" ; ito.LOE__c = "{!TicketMGNT__Incident__c.Estimated_Level_of_Effort__c}" ; ito.IncidentID__c = '{!TicketMGNT__Incident__c.Name}' ; ito.CurrencyIsoCode = '{!TicketMGNT__Incident__c.CurrencyIsoCode}' ; ito.Account__c = "{!TicketMGNT__Incident__c.TicketMGNT__FKAccountId__c}" ; ito.Incident_Owner__c = '{!TicketMGNT__Incident__c.TicketMGNT__FKOpenById__c}' ; ito.Price__c = "{!TicketMGNT__Incident__c.Price__c}"; ito.Subject__c = "{!TicketMGNT__Incident__c.Subject__c}" ; ito.Combined_Total_Duration_Minutes__c = '{!TicketMGNT__Incident__c.Combined_Total_Duration__c}' ; var inote = new sforce.SObject('TicketMGNT__IncidentHistory__c'); inote.Name = '{!TicketMGNT__Incident__c.Name}' ; inote.TicketMGNT__FKAction__c = 'a0Y20000009ry5LEAQ' ; inote.TicketMGNT__description__c = 'Billing Opportunity Sent' ; inote.TicketMGNT__date__c = thedatetime ; inote.TicketMGNT__FKUser__c = '{!User.Id}' ; inote.TicketMGNT__FKIncident__c = '{!TicketMGNT__Incident__c.Id}' ; inote.TicketMGNT__duration__c = "00:15" ; result = sforce.connection.create([ito]); result = sforce.connection.create([inote]); if(result[0].success == 'true'){ alert('An New ito - ' + ito.Name + ' was Created Successfully.'); } else{ alert( "An Error has Occurred.\r\n The Invoice Note, ELOE, and Billing Work Type must be populated.\r\n" + "Error: " + result[0].errors.message ); } else { alert('billingworktype Is Empty'); }
but now nothing happens. The oringal button looked like this:
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')} getDate = function(dateObj){ var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay(); var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth(); return dateObj.getFullYear()+'-'+month+'-'+day; } var thedatetime = function xsdDateTime(date) { function pad(n) { var s = n.toString(); return s.length < 2 ? '0'+s : s; }; var yyyy = date.getFullYear(); var mm1 = pad(date.getMonth()+1); var dd = pad(date.getDate()); var hh = pad(date.getHours()); var mm2 = pad(date.getMinutes()); var ss = pad(date.getSeconds()); return yyyy +'-' +mm1 +'-' +dd +'T' +hh +':' +mm2 +':' +ss; } var ito = new sforce.SObject('Incident2Op__c'); ito.Name = '{!BMCServiceDesk__Incident__c.Name}'; ito.OwnerId = '{!User.Id}'; ito.Note1__c = "{!BMCServiceDesk__Incident__c.Invoice_Note__c}" ; ito.WorkType__c = '{!BMCServiceDesk__Incident__c.Billing_Work_Type__c}' ; ito.Category__c = "{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c }" ; ito.LOE__c = "{!BMCServiceDesk__Incident__c.Estimated_Level_of_Effort__c}" ; ito.IncidentID__c = '{!BMCServiceDesk__Incident__c.Name}' ; ito.CurrencyIsoCode = '{!BMCServiceDesk__Incident__c.CurrencyIsoCode}' ; ito.Account__c = "{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKAccountId__c}" ; ito.Incident_Owner__c = '{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKOpenById__c}' ; ito.Price__c = "{!BMCServiceDesk__Incident__c.Price__c}"; ito.Subject__c = "{!BMCServiceDesk__Incident__c.Subject__c}" ; ito.Combined_Total_Duration_Minutes__c = '{!BMCServiceDesk__Incident__c.Combined_Total_Duration__c}' ; var inote = new sforce.SObject('BMCServiceDesk__IncidentHistory__c'); inote.Name = '{!BMCServiceDesk__Incident__c.Name}' ; inote.BMCServiceDesk__FKAction__c = 'a0Y20000009ry5LEAQ' ; inote.BMCServiceDesk__description__c = 'Billing Opportunity Sent' ; inote.BMCServiceDesk__date__c = thedatetime ; inote.BMCServiceDesk__FKUser__c = '{!User.Id}' ; inote.BMCServiceDesk__FKIncident__c = '{!BMCServiceDesk__Incident__c.Id}' ; inote.BMCServiceDesk__duration__c = "00:15" ; result = sforce.connection.create([ito]); result = sforce.connection.create([inote]); if(result[0].success == 'true'){ alert('An New ito - ' + ito.Name + ' was Created Successfully.'); } else{ alert( "An Error has Occurred.\r\n The Invoice Note, ELOE, and Billing Work Type must be populated.\r\n" + "Error: " + result[0].errors.message ); }
you can see the changes i made on line 25 where i defined billingwork type
line 27 i made an if statement
line 69/72 i deal with the if statement.
I hope someone can give me a good lesson on how this should work
Cheers
Dale
Rajiv Penagonda 12
Dale, what does the variable "text" refer to in line #27? Can you try your button on a tool like Firebug and see what message is shown in the console?