Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Window

Status
Not open for further replies.

zishan876

Programmer
Mar 19, 2007
61
US
Hi all:
I have code that would loop through a recordset depending on how many id's are selected. I would like to pop open a window and print recordset out.
Code:
/ DECLARE CONSTANTS
var POS_ID="{!Case.Id}";
var POP_MSG="";

function getApps()
{
// This function retrieves the User selected records
try
{
var recordIds = {!GETRECORDIDS($ObjectType.Case)};
//

//my if then statement
if (recordIds.length > 0) 
{
var records = sforce.connection.retrieve("Id,Ticket_Origin__c, Subject, Status, Reason_Detail__c, Reason, Description, CaseNumber, Acct_Owner__c, AS400_Account_Number__c","Case",recordIds);
alert("You have select cases with Ids of " + recordIds);
} 
else 
{ POP_MSG += "\r\nNo Records Selected\r\n"; }
} catch (e){POP_MSG += "\r\nERROR\r\n" + e;}
return records;
}

function printall(records)
{
var str="";

for (i=0;i<records.length;i++)
{

str +='<tr><td>' + records[i].Id+ '</td><td>' + records[i].CaseNumber +'</td></tr>';
}
alert(str);
}
var records=getApps();
if (records !=null)
{
if (records.length >0) {
printall(records);
}
}
alert(POP_MSG);
does anyone know how to do this?
Thanks
It is a button firing this off...
 
What have you tried/researched so far? There appear to be lots of solutions available to do this (did a simple google search)... and I wouldn't want to repeat stuff you've already attempted.

There is also an FAQ section in the forum that gives some specifics on how to use javascript to print... it'd make a good starting point.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thank for replying Back to me... Well I tried window.print, printwin, window.open <== that was not good...
I guess I just don't know how to start the process.. This is my first time doing print functions in javascript.. kind of like a print preview and all...
Thanks
Any help would be appreciated..
 
I would suggest you look at using window.open() and document.write() out the contents of your function to that popup (sounds you had a bad experience with window.open() - you'll have to suck it up [smile]). You can then supply a stylesheet for it and include a call to window.print() for when the content is fully written.

The user would be left with a "Close" button that merely does a self.close() when clicked. It's probably better to do this that attempt to determine when it is otherwise safe to close it automatically.

I think it's the best way to achieve your functionality (and gives you flexibility to change the style of the content later without doctoring "deeper" code).

CHeers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
hi all:
So now my code looks like this:
Code:
{! requireScript("/soap/ajax/10.0/connection.js") } 

// DECLARE CONSTANTS
var POS_ID="{!Case.Id}";
var POP_MSG="";

function getApps(){
// This function retrieves the User selected records
try{var recordIds = {!GETRECORDIDS($ObjectType.Case)};
if (recordIds.length > 0) 
{var records = sforce.connection.retrieve("Id,Ticket_Origin__c, Subject, Status, Reason_Detail__c, Reason, Description, CaseNumber, Acct_Owner__c, AS400_Account_Number__c","Case",recordIds);
alert("You have select cases with Ids of " + recordIds);
} 
else 
 { POP_MSG += "\r\nNo Records Selected\r\n"; }
} catch (e){POP_MSG += "\r\nERROR\r\n" + e;}
return records;
}


function dirtypop()
{
  var generator=window.open('','name','height=400,width=500');
  
  generator.document.write('<html><head><title>Selected Cases</title>');
  generator.document.write('<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script> ');
  generator.document.write('<script type="text/javascript"> ');
  generator.document.write('var records=getApps();alert("your" + records.length);');
  generator.document.write('function printall(records){');
  generator.document.write('var str="";for (i=0;i<records.length;i++){');
  generator.document.write('str +="<tr><td>" + records[i].Id + "</td><td>" + records[i].CaseNumber +"</td></tr>";}');
  generator.document.write('document.getElementById("div_tag").innerHTML = str;}');
  generator.document.write('</script></head><body>');
  generator.document.write('<p><div id="div_tag">No Accts</div> </p>');
  generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
  generator.document.write('</body></html>');
  generator.document.close();
}
var records=getApps();if (records !=null){if (records.length >0) {dirtypop();}}
alert(POP_MSG);
for some reason my pop up window is blank?? how do I call a function within dirtypop function...
Thanks
 
Why not do all the javascript stuff (database lookup) in the dirtypop() method - instead of attempting to do the database lookup etc using the popup itself? You can use javascript to then just trigger the window.print() from the main page to the popup window. You shouldn't have the need to do any javascript in the popup window itself (so the problem goes away).

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hi:
Thank you... But do you have an example of that because I am totally lost now...
Please
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top