Create button and give name "b".
create dynamic text and give name "tampil".
Run it... Click on b button to run the timer, and click again to stop(but error).
The following script is a piece of my project that I modified.
My question is, how do I stop the timer?
import flash.events.MouseEvent;
var xx:Number = 1;
var waktux:Timer;
var i1:Number = 1;
var ab:Number = 1;
var lantaii:String = "lg";
b.addEventListener(MouseEvent.CLICK, stopp);
function stopp(e:MouseEvent)
{
waktu(0,0,ab);
if (ab==1)
{
ab = 0;
}
else
{
ab = 1;
}
}
function waktu(e, d, cx)
{
var waktux:Timer;
var waktuy:Timer;
function sayHello(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
function sayHellow(e:TimerEvent):void
{
tampil.text = String(d);
d = d + 1;
}
function sayHello2(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
if (cx==1)
{
if (lantaii == "lg")
{
naek();
}
else
{
waktuy = new Timer(400,10);
waktuy.addEventListener(TimerEvent.TIMER, sayHellow);
waktuy.start();
waktuy.addEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
function naek()
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello);
waktux.start();
}
function naek2(s:TimerEvent):void
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello2);
waktux.start();
}
}
else
{
trace("nih masuk");
waktux.stop();
waktux.reset();
waktuy.reset();
waktux.removeEventListener(TimerEvent.TIMER, sayHello);
waktux.removeEventListener(TimerEvent.TIMER, sayHello2);
waktuy.removeEventListener(TimerEvent.TIMER, sayHellow);
waktuy.removeEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
}
I think you redefine waktux one in global scope and other in waktu function.
delete one of these lines
import flash.events.MouseEvent;
var xx:Number = 1;
var waktux:Timer; //<--------------------------- HERE
var i1:Number = 1;
var ab:Number = 1;
var lantaii:String = "lg";
function waktu(e, d, cx)
{
var waktux:Timer; //<--------------------------- HERE
var waktuy:Timer;
function sayHello(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
function sayHellow(e:TimerEvent):void
{
tampil.text = String(d);
d = d + 1;
}
function sayHello2(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
if (cx==1)
{
if (lantaii == "lg")
{
naek();
}
else
{
waktuy = new Timer(400,10);
waktuy.addEventListener(TimerEvent.TIMER, sayHellow);
waktuy.start();
waktuy.addEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
function naek()
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello);
waktux.start();
}
function naek2(s:TimerEvent):void
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello2);
waktux.start();
}
}
else
{
trace("nih masuk");
waktux.stop();
waktux.reset();
waktuy.reset();
waktux.removeEventListener(TimerEvent.TIMER, sayHello);
waktux.removeEventListener(TimerEvent.TIMER, sayHello2);
waktuy.removeEventListener(TimerEvent.TIMER, sayHellow);
waktuy.removeEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
}
and just for fun
function stopp(e:MouseEvent)
{
waktu(0,0,ab);
ab = !ab;
}
Related
I have a 200 pages long google document containing some complex data like tables, paragraph and hyperlinks.
I am trying to create a custom dialog box or button with two option "next" and "Previous".
So Whenever I click on "next" it should set my cursor on next hyperlink in google doc for example if I am on page 30 and there is hyper link on page 31 too I want to jump over next hyperlink or position.
So far I am able to get all hyperlink through out the document but I don't how to set my cursor over those word or jump over to next or previous hyperlink by clicking on button in dialog box.
code.gs
function highlightLink3() {
const doc = DocumentApp.getActiveDocument()
const body = doc.getBody()
const text = body.getText();
const words = [...new Set(text.split(/[\n ]/g).map(e => e.trim()).filter(String))];
words.forEach(t => {
let word = body.findText(t);
while (word) {
const e = word.getElement();
const start = word.getStartOffset();
if (e.getLinkUrl(start)) {
doc.setCursor(e.getLinkUrl(start))
}
word = body.findText(t, word);
}
});
}
So far I am able to get all hyperlink through out the document but I don't how to set my cursor over those word or jump over to next or previous hyperlink by clicking on button in dialog box.
Here is something I created a while back. If constructs a tree view of my document based on the Headers. I create a side bar and can navigate down the tree. When I click on an item it directs me to that header.
My Document was 93 pages so I developed this to navigate back and forth. Otherwise you would have to return to the table of contents every time to go to another section.
Code.gs
function onOpen() {
var thisMenu = DocumentApp.getUi().createMenu('Test');
thisMenu.addItem('Treeview in Code.gs', 'treeViewOnOpen').addToUi();
}
function treeViewOnOpen() {
try {
var html = HtmlService.createTemplateFromFile("HTML_TreeView");
html = html.evaluate();
DocumentApp.getUi().showSidebar(html);
}
catch(err) {
Logger.log("Error in treeViewOnOpen: "+err);
}
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
function TreeNode(level,name) {
this.parent = null;
this.level = level;
this.name = name;
this.children = [];
this.link = null
}
function ToCListItem(level,text) {
this.level = level;
this.text = text;
var time = new Date();
this.link = "h"+level.toString()+"_"+time.getTime().toString();
}
function getTreeView() {
try {
var doc = DocumentApp.getActiveDocument();
var bod = doc.getBody();
var pars = bod.getParagraphs();
var root = new TreeNode(0,"Root");
var parent = root;
var level = 1;
var last = null;
for( var i=0; i<pars.length; i++ ) {
var par = pars[i];
var head = getHeading(par);
if( par.getText().trim() === "" ) continue;
if( head > 0 ) {
var node = new TreeNode(head,par.getText());
var link = par.getLinkUrl();
if( !link ) {
var time = new Date();
node.link = "h"+head.toString()+"_"+time.getTime().toString();
par.setLinkUrl(node.link);
}
else {
node.link = link;
}
if( head > level ) {
parent = last;
level = head;
}
else if( head < level ) {
while( head <= level ) {
parent = parent.parent;
level = parent.level;
}
if( level === 0 ) level = 1;
}
node.parent = parent;
parent.children.push(node);
last = node;
}
}
var s = "";
for( var i=0; i<root.children.length; i++ ) {
s = s + stringify(root.children[i]);
}
return s;
}
catch(err) {
Logger.log("Error in getTreeView: "+err);
}
}
function stringify(tree) {
try {
var s = ""
if( tree.children.length > 0 ) {
s = "<li><input class='node' type='button' value='+'>"+tree.name+"\n";
s = s + "<ul>\n";
for( var i=0; i<tree.children.length; i++ ) {
s = s + stringify(tree.children[i]);
}
s = s + "</ul>\n</li>\n";
}
else {
var s = "<li class='link' id='"+tree.link+"'><input class='link' type='button' value=' '>"+tree.name+"</li>\n";
}
return s;
}
catch(err) {
Logger.log(err);
}
}
function getHeading(par) {
try {
var head = par.getHeading();
if( head == DocumentApp.ParagraphHeading.HEADING1 ) {
return 1;
}
else if( head == DocumentApp.ParagraphHeading.HEADING2 ) {
return 2;
}
else if( head == DocumentApp.ParagraphHeading.HEADING3 ) {
return 3;
}
else if( head == DocumentApp.ParagraphHeading.HEADING4 ) {
return 4;
}
else if( head == DocumentApp.ParagraphHeading.HEADING5 ) {
return 5;
}
else if( head == DocumentApp.ParagraphHeading.HEADING6 ) {
return 6;
}
return -1;
}
catch(err) {
Logger.log("Error in getHeading: "+err);
}
}
function linkClick(link) {
try {
var doc = DocumentApp.getActiveDocument();
var bod = doc.getBody();
var pars = bod.getParagraphs();
for( var i=0; i<pars.length; i++ ) {
var par = pars[i];
var head = getHeading(par);
if( head > 0 ) {
if( par.getLinkUrl() == link ) {
var pos = doc.newPosition(par.getChild(0),0);
doc.setCursor(pos);
return;
}
}
}
}
catch(err) {
Logger.log("Error in setCursor: "+err);
}
}
HTML_TreeView
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('CSS_TreeView'); ?>
</head>
<body>
<ul class="tree">
<?!= getTreeView(); ?>
</ul>
<?!= include('JS_TreeView'); ?>
</body>
</html>
CSS_TreeView
<style>
body {
font-family: Arial;
font-size: small;
}
ul.tree li {
list-style-type: none;
position: relative;
}
ul.tree li ul {
display: none;
}
ul.tree li.open > ul {
display: block;
}
ul.tree li input {
color: black;
text-decoration: none;
margin-right: 10px;
width: 25px;
}
ul.tree li input:before {
height: 1em;
padding: 0 .1em;
font-size: .8em;
display: block;
position: absolute;
left: -1.3em;
top: .2em;
}
</style>
JS_TreeView
<script>
function expandClick(e) {
try {
var parent = e.target.parentElement;
var classList = parent.classList;
if(classList.contains("open")) {
classList.remove('open');
var opensubs = parent.querySelectorAll(':scope .open');
for(var i = 0; i < opensubs.length; i++){
opensubs[i].classList.remove('open');
}
e.target.value = "+";
}
else {
classList.add('open');
e.target.value = "-";
}
}
catch(err) {
alert(err);
}
}
function linkClick(e) {
try {
var id = e.target.id;
if( id === "" ) id = e.target.parentNode.id;
google.script.run.linkClick(id);
}
catch(err) {
alert(err);
}
}
(function () {
try {
var tree = document.querySelectorAll('ul.tree input.node');
for(var i = 0; i < tree.length; i++) {
tree[i].addEventListener('click', expandClick);
}
var tree = document.querySelectorAll('ul.tree li.link');
for(var i = 0; i < tree.length; i++) {
tree[i].addEventListener('click', linkClick);
}
}
catch(err) {
alert(err);
}
})();
</script>
I've constructed a "Conveyor" style system within Google Sheets to move users from further slots into closer slots when they become available.
Screenshot of the Google Sheets layout where this is being implemented.
For example, if someone was in "User 1" but then left, it moves the user in "User 2" into "User 1", the user in "User 3" moves to "User 2", etc., pushing them along the chain, ensuring that the slots are used in order.
As the requirements are time-based, it's often the case that Users 1, 2 and 3 are removed at the same time, meaning that one person is left in the "User 4" slot. Using the current script, it will move them from "User 4" -> "User 3" -> "User 2" -> "User 1".
Additionally, due to some formatting I have set up (Index Matching), I need the cells to display the word "None" instead of staying blank. I've been able to do this easily by checking if the cell is blank, and if so, setting the value to "None".
The script works, but it is really slow. The total script execution time is over 14 seconds.
Here's the scripting I'm using:
function conveyor() {
var s = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName('UsernameSheet');
// LOOP 1
var Username1Val = s.getRange('C3').getDisplayValue();
var Username2Val = s.getRange('I3').getDisplayValue();
var Username3Val = s.getRange('O3').getDisplayValue();
var Username4Val = s.getRange('U3').getDisplayValue();
var Username1 = s.getRange('C3')
var Username2 = s.getRange('I3')
var Username3 = s.getRange('O3')
var Username4 = s.getRange('U3')
if (Username3Val == 'None') {
FourtoThree();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
if (Username2Val == 'None') {
ThreetoTwo();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
if (Username1Val == 'None') {
TwotoOne();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
// LOOP 2
var Username1Val = s.getRange('C3').getDisplayValue();
var Username2Val = s.getRange('I3').getDisplayValue();
var Username3Val = s.getRange('O3').getDisplayValue();
var Username4Val = s.getRange('U3').getDisplayValue();
var Username1 = s.getRange('C3')
var Username2 = s.getRange('I3')
var Username3 = s.getRange('O3')
var Username4 = s.getRange('U3')
if (Username3Val == 'None') {
FourtoThree();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
if (Username2Val == 'None') {
ThreetoTwo();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
if (Username1Val == 'None') {
TwotoOne();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
// LOOP 3
var Username1Val = s.getRange('C3').getDisplayValue();
var Username2Val = s.getRange('I3').getDisplayValue();
var Username3Val = s.getRange('O3').getDisplayValue();
var Username4Val = s.getRange('U3').getDisplayValue();
var Username1 = s.getRange('C3')
var Username2 = s.getRange('I3')
var Username3 = s.getRange('O3')
var Username4 = s.getRange('U3')
if (Username3Val == 'None') {
FourtoThree();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
if (Username2Val == 'None') {
ThreetoTwo();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
if (Username1Val == 'None') {
TwotoOne();
}
if (Username1.isBlank()) {
Username1.setValue('None');
}
if (Username2.isBlank()) {
Username2.setValue('None');
}
if (Username3.isBlank()) {
Username3.setValue('None');
}
if (Username4.isBlank()) {
Username4.setValue('None');
}
}
function FourtoThree() {
var s = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName('UsernameSheet');
var Username3Name = s.getRange('O3');
var Username3NameVal = s.getRange('O3').getDisplayValue();
var Username3Start = s.getRange('O4');
var Username3StartVal = s.getRange('O4').getDisplayValue();
var Username3Finish = s.getRange('O5');
var Username3FinishVal = s.getRange('O5').getDisplayValue();
var Username3Break = s.getRange('Q7');
var Username3BreakVal = s.getRange('Q7').getDisplayValue();
var Username3Busy = s.getRange('Q6');
var Username3BusyVal = s.getRange('Q6').getDisplayValue();
var Username4Name = s.getRange('U3');
var Username4NameVal = s.getRange('U3').getDisplayValue();
var Username4Start = s.getRange('U4');
var Username4StartVal = s.getRange('U4').getDisplayValue();
var Username4Finish = s.getRange('U5');
var Username4FinishVal = s.getRange('U5').getDisplayValue();
var Username4Break = s.getRange('W7');
var Username4BreakVal = s.getRange('W7').getDisplayValue();
var Username4Busy = s.getRange('W6');
var Username4BusyVal = s.getRange('W6').getDisplayValue();
Username3Name.setValue(Username4NameVal);
Username3Start.setValue(Username4StartVal);
Username3Finish.setValue(Username4FinishVal);
Username3Break.setValue(Username4BreakVal);
Username3Busy.setValue(Username4BusyVal);
Username4Name.clearContent();
Username4Start.clearContent();
Username4Finish.clearContent();
Username4Break.clearContent();
Username4Busy.clearContent();
}
function ThreetoTwo() {
var s = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName('UsernameSheet');
var Username2Name = s.getRange('I3');
var Username2NameVal = s.getRange('I3').getDisplayValue();
var Username2Start = s.getRange('I4');
var Username2StartVal = s.getRange('I4').getDisplayValue();
var Username2Finish = s.getRange('I5');
var Username2FinishVal = s.getRange('I5').getDisplayValue();
var Username2Break = s.getRange('K7');
var Username2BreakVal = s.getRange('K7').getDisplayValue();
var Username2Busy = s.getRange('K6');
var Username2BusyVal = s.getRange('K6').getDisplayValue();
var Username3Name = s.getRange('O3');
var Username3NameVal = s.getRange('O3').getDisplayValue();
var Username3Start = s.getRange('O4');
var Username3StartVal = s.getRange('O4').getDisplayValue();
var Username3Finish = s.getRange('O5');
var Username3FinishVal = s.getRange('O5').getDisplayValue();
var Username3Break = s.getRange('Q7');
var Username3BreakVal = s.getRange('Q7').getDisplayValue();
var Username3Busy = s.getRange('Q6');
var Username3BusyVal = s.getRange('Q6').getDisplayValue();
Username2Name.setValue(Username3NameVal);
Username2Start.setValue(Username3StartVal);
Username2Finish.setValue(Username3FinishVal);
Username2Break.setValue(Username3BreakVal);
Username2Busy.setValue(Username3BusyVal);
Username3Name.clearContent();
Username3Start.clearContent();
Username3Finish.clearContent();
Username3Break.clearContent();
Username3Busy.clearContent();
}
function TwotoOne() {
var s = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName('UsernameSheet');
var Username1Name = s.getRange('C3');
var Username1NameVal = s.getRange('C3').getDisplayValue();
var Username1Start = s.getRange('C4');
var Username1StartVal = s.getRange('C4').getDisplayValue();
var Username1Finish = s.getRange('C5');
var Username1FinishVal = s.getRange('C5').getDisplayValue();
var Username1Break = s.getRange('E7');
var Username1BreakVal = s.getRange('E7').getDisplayValue();
var Username1Busy = s.getRange('E6');
var Username1BusyVal = s.getRange('E6').getDisplayValue();
var Username2Name = s.getRange('I3');
var Username2NameVal = s.getRange('I3').getDisplayValue();
var Username2Start = s.getRange('I4');
var Username2StartVal = s.getRange('I4').getDisplayValue();
var Username2Finish = s.getRange('I5');
var Username2FinishVal = s.getRange('I5').getDisplayValue();
var Username2Break = s.getRange('K7');
var Username2BreakVal = s.getRange('K7').getDisplayValue();
var Username2Busy = s.getRange('K6');
var Username2BusyVal = s.getRange('K6').getDisplayValue();
Username1Name.setValue(Username2NameVal);
Username1Start.setValue(Username2StartVal);
Username1Finish.setValue(Username2FinishVal);
Username1Break.setValue(Username2BreakVal);
Username1Busy.setValue(Username2BusyVal);
Username2Name.clearContent();
Username2Start.clearContent();
Username2Finish.clearContent();
Username2Break.clearContent();
Username2Busy.clearContent();
}
What the script does is Firstly runs to check if the usernames 1-4 have a blank cell. If they do, they set the values to "None".
Then, an IF statement runs to check if Username 3 = None, if it does, it then runs function FourtoThree, which in itself moves the values from Username 4 to Username 3. It then checks Username 2, then username 1, and does the same type of functions of moving the data along if the value is "None". This whole function then runs 3 times, the maximum number of moves the conveyor system would need to complete.
I'm still a novice with Google Apps Script (well, JavaScript in general), so I threw this together and was happy it worked.
Now, the sluggish runtime of the script is becoming problematic for its use-scenario , and I'm looking for ways to optimize this, please.
I'm not at all expecting anyone to write me a script that would alleviate my issues, but if anyone could suggest an example of a function that could achieve what I'm trying to do, and/or an idea of how to implement it.
Here is a prototype you can try but I don't use "None" just blank
function conveyor() {
var s = SpreadsheetApp.getActiveSpreadsheet();
// Get range C3:W7
var r = s.getSheetByName('Test').getRange(3,3,5,21);
var users = r.getValues();
var formulas = r.getFormulas();
for( var i=0; i<13; i+=6 ) { // Only do it 3 times
if( users[0][i] === "" ) {
users[0][i] = users[0][i+6]; // Username
users[0][i+6] = "";
users[1][i] = users[1][i+6]; // Start time
users[1][i+6] = "";
users[2][i] = users[2][i+6]; // Finish time
users[2][i+6] = "";
users[3][i+2] = users[3][i+8]; // Busy
users[3][i+8] = false;
users[4][i+2] = users[4][i+8]; // Break
users[4][i+8] = false;
}
}
for( var i=0; i<users.length; i++ ) {
for( var j=0; j<users[0].length; j++ ) {
if( formulas[i][j] !== "" ) users[i][j] = formulas[i][j].toString();
}
}
r.setValues(users);
}
I have a script set up to extract figures from a csv file into a webpage. We have a problem in that a figure that have a 0 after the decimal point is being ignored so whilst the csv file shows 1.094 when teh figure is transferred to the webpage it is 1.94
There is a js script and then an asp script that works the function
function getHTTPObject()
{
var x = null;
if (window.XMLHttpRequest)
{
x = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
x = new ActiveXObject("Microsoft.XMLHTTP");
if (!x)
{
x = new ActiveXObject("Msxml2.XMLHTTP");
}
}
return x;
}
var gobj = getHTTPObject();
window.onload=update();
function update()
{
var xpath = "ratesxtract.asp";
if (gobj) {
gobj.open("GET", xpath, true);
gobj.onreadystatechange = update_all;
gobj.send(null);
}
else {alert("XMLHTTP access problem. Please exit page and try again" ); }
}
function update_all()
{
if (gobj.readyState == 4) {
if (gobj.status == 200) {
// dobj = document.getElementById("BLastUpdated");
var A = gobj.responseText;
// dobj.innerHTML = A;
if (A == "error") {alert("XMLHTTP access problem. Please exit page and contact us" ); }
else { processfile(A); }
}
}
function processfile(A)
{
var errormess = "none";
var AA = new String(A);
AA = AA.split("$");
var nName = null;
var dobj = null;
var nValue = null;
var i = 0;
for (i = 0; i < AA.length; i++) {
if (AA[i].charAt(0) == "Z") {
nName = AA[i];
dobj = document.getElementById(nName);
}
else { nValue = "";
nValue += AA[i];
dobj.innerHTML = nValue;
}
}
if ( i == 0 ) { errormess = "failed to access exchange rates data, please exit page and try again";
alert(errormess)
}
}
ASP SCRIPT
<%#LANGUAGE='JScript'%>
<%
var sfile = Server.MapPath("forex\\ratefile.csv");
var fs = Server.CreateObject("Scripting.FileSystemObject");
var fsT = fs.OpenTextFile(sfile, 1, 0);
var xline;
var p = 0;
var q = 0;
var d = 0;
var i = 0;
var n = 0;
var t = 0;
var ts = 0;
var mname;
var mprice;
var mtime = "";
var INLine
var LN;
var cresult = "";
while(!fsT.AtEndOfStream) {
INLine = fsT.ReadLine();
xline = String(INLine);
if ( p != 0) {
LN = xline.split(",");
mname = xtrim(LN[0]);
mprice = doamount3(LN[1]);
if (p == 1) { mtime = xtrim(LN[2]); }
if (n > 0){ cresult += "$"; }
n++;
cresult += "Z" + mname + "$" + mprice;
}
p++;
}
cresult += "$ZTIM$" + mtime;
fsT.Close();
Response.Write(cresult);
%>
<%
function xtrim(x)
{
var xd = x.replace(/^\s+|\s+$/gm,'');
return xd;
}
function doamount3(amt)
{
var ZLine = String(amt);
ZLine = xtrim(ZLine);
if (ZLine.indexOf(".") == -1) {
ZLine += ".00";
return(ZLine);
}
var idata = ZLine.split(".");
var xadp = new String(idata[1]);
var xlen = xadp.length;
if (xlen == 1) {
idata[1] = xadp + "00";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
if (xlen == 2) {
idata[1] = xadp + "0";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
var p4 = xadp.charAt(3);
var p3 = parseInt(xadp.substring(0,3), 10);
if (p4 > 4) { p3 += 0; }
idata[1] = String(p3);
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
%>
If anyone can help be greatly appreciated
The onload event is firing and I am not getting any erroors, but the calculated field is not refreshing?
It should be doing the calculation from the function FWeightedValue().
Here is the code, any help would be appreciated.
frmOnLoad();
onLoad = false;
}
catch(e)
{ alert(e.message); }
}//End of if condition
}//End of function
/* Declare Variables */
var onLoad = true;
var sGlobalVar = '';
function frmOnLoad()
{ ResizeScreen();
AddLogoToFormTitle(160, "/CRM4Legal/_imgs/reznick_small.gif");
fldMerge('name');
fldMerge('customerid');
fldMerge('rg_officeid');
fldStatus();
fldGSMC();
FWeightedValue();
frmTabs();
frmNav();
frmIFrames();
if ($("rg_gsmc" ) != null) $("rg_gsmc" ).onclick = fldGSMC;
}
function FWeightedValue()
{ with ( crmForm.all )
var EstRev = crmForm.getAttribute("estimatedvalue").getValue();
var RiskWeight = Xrm.Page.getAttribute("cpdc_riskweight").getValue();
var RiskPercent = RiskWeight / 100;
Xrm.Page.data.entity.attributes.get("cpdc_riskweightedvalue").setValue(RiskWeightValue);
sectionDisplay( true, cpdc_riskweightedvalue);
}
FWeightedValue.NullCheck = function (value)
{
if (value == null) {
return 0.0;
} else {
return value;
}
}
}
function fldStatus()
{ with ( crmForm.all )
{ if ( statuscode.SelectedText == 'Won' || statuscode.SelectedText == 'Lost' )
{ crmForm.SetFieldReqLevel("rg_winlossreason", 1);
sectionDisplay( false, rg_winlossreason );
}
else
{ crmForm.SetFieldReqLevel("rg_winlossreason", 0);
rg_winlossreason.DataValue = null;
sectionDisplay( true, rg_winlossreason );
}
}
}
function fldGSMC()
{ with ( crmForm.all )
{ sectionDisplay( !rg_gsmc.DataValue, rg_contractnumber );
crmForm.SetFieldReqLevel("rg_contracttype", ( rg_gsmc.DataValue ? 1 : 0 ));
}
}
function fldMerge(fld)
{ if ( fld == null ) { return; }
var cell = $(fld + '_d');
if ( cell == null ) { return; }
var row = cell.parentNode;
if ( row == null ) { return; }
cell.colSpan = 3;
row.removeChild(cell.nextSibling);
row.removeChild(cell.nextSibling);
}
function frmTabs()
{ tab('Hidden', 'hidden');
}
function frmNav()
{ navHide ('nav_rg_opportunity_rg_opportunitypracticearea');
navHide ('nav_rg_opportunity_rg_opportunityservicearea');
navHide ('nav_rg_opportunity_rg_engagementteam');
navHide ('nav_rg_opportunity_rg_opportunityteam');
navHide ('navProducts');
navHide ('navQuotes');
navHide ('navOrders');
navHide ('navInvoices');
navHide ('navComp');
navHide ('_NA_SFA');}
function frmIFrames()
{ /* Engagement Team */
var n2nPA = new N2NViewer('IFRAME_EngagementTeam');
/* Set the role order - use iedevtoolber for exact parameters */
n2nPA.RoleOrder = 1;
/* assing the relationship name (without the "area" word) */
n2nPA.TabsetId = "rg_opportunity_rg_engagementteam";
n2nPA.Load();
/* Opportunity Team */
var n2nPA = new N2NViewer('IFRAME_OpportunityTeam');
n2nPA.RoleOrder = 1;
n2nPA.TabsetId = "rg_opportunity_rg_opportunityteam";
n2nPA.Load();
/* Practice Areas */
var n2nPA = new N2NViewer('IFRAME_PracticeAreas');
n2nPA.RoleOrder = 1;
n2nPA.TabsetId = "rg_opportunity_rg_opportunitypracticearea";
n2nPA.Load();
/* Service Areas */
var n2nService = new N2NViewer('IFRAME_Services');
n2nService.RoleOrder = 1;
n2nService.TabsetId = "rg_opportunity_rg_opportunityservicearea";
n2nService.Load();
}
function $(name)
{ return document.getElementById(name);
}
function navHide (name)
{ if ($(name) != null) { $(name).style.display = "none"; }
}
function tab ( tabName, tabVisibility )
{ tabVisibility = ( tabVisibility == "visible" ? "" : "none" );
var _tabs = crmForm.getElementsByTagName("li");
for (var i = 0; i < _tabs.length; i++)
{ var _tab = _tabs[i];
if ( _tab.innerText == tabName )
{ _tab.style.display = tabVisibility;
break;
}
}
}
function sectionDisplay(vis, sec)
{ sec.parentElement.parentElement.parentElement.style.display = ((vis) ? 'none' : 'block');
}
function ResizeScreen()
{ var aH = screen.availHeight;
var aW = screen.availWidth;
var top = 0;
var left = 0;
if ( aW >= 1124 && aH >= 800)
{ var aH = (aH > 800 ? 800 : 768);
var aW = 1124;
var top = (screen.availHeight - aH) / 2;
var left = (screen.availWidth - aW) / 2;
}
// aH = (crmForm.FormType == frmType.Create ? 295 : aH);
window.moveTo(left, top);
window.resizeTo(aW, aH);
}
function N2NViewer(iframeId)
{ if (!document.all[iframeId])
{ alert(iframeId + " is missing!");
return;
}
var viewer = this;
var _locAssocObj = null;
viewer.IFRAME = document.all[iframeId];
viewer.RoleOrder;
viewer.TabsetId;
viewer.Load = function()
{ if (crmForm.ObjectId != null)
{ /* Construct a valid N2N IFRAME url */
viewer.IFRAME.src = "areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=" + crmFormSubmit.crmFormSubmitSecurity.value + "&roleOrd=" + viewer.RoleOrder + "&tabSet=" + viewer.TabsetId;
viewer.IFRAME.onreadystatechange = viewer.StateChanged;
}
else
{ viewer.IFRAME.src = "about:blank";
}
}
viewer.StateChanged = function()
{ if (viewer.IFRAME.readyState != 'complete')
{ return;
}
var iframeDoc = viewer.IFRAME.contentWindow.document;
/* Reomve scrolling space */
iframeDoc.body.scroll = "no";
/* Remove crmGrid Default padding */
iframeDoc.body.childNodes[0].rows[0].cells[0].style.padding = 0;
/* Save MS locAssocObj */
_locAssocObj = locAssocObj;
/* Override MS locAssocObj */
locAssocObj = viewer.locAssocObj;
}
viewer.locAssocObj = function(iType , sSubType, sAssociationName, iRoleOrdinal)
{ /* Open the Dialog */
_locAssocObj(iType , sSubType, sAssociationName, iRoleOrdinal);
/* Refresh only if our iframe contains the correnct tabset name */
if (sAssociationName == viewer.TabsetId)
{ viewer.IFRAME.contentWindow.document.all.crmGrid.Refresh();
}
}
}
function AddLogoToFormTitle(logoWidth, logoUrl)
{ var formTitleTable = null;
var tables = document.getElementsByTagName("table");
for(var i = 0; i < tables.length; i++)
{ var className = tables[i].className;
if (className && className.indexOf("ms-crm-Form-Title") == 0)
{ formTitleTable = tables[i];
break;
}
}
if (formTitleTable)
{ var newCell = formTitleTable.rows[0].insertCell(2);
newCell.width = logoWidth;
newCell.vAlign = "middle";
newCell.innerHTML = '<img src="'+logoUrl+'" border="0" align="right" />';
}
}
function UnUsed()
{
if(false)
{
try
{
You mixed CRM 4.0 and CRM 2011 SDKs. No wonder nothing is working!
Below is what should be written if your target platform is CRM 4.0
function FWeightedValue()
{
var EstRev = crmForm.estimatedvalue.DataValue;
var RiskWeight = crmForm.cpdc_riskweight.DataValue;
var RiskPercent = RiskWeight / 100;
crmForm.cpdc_riskweightedvalue.DataValue = RiskWeightValue;
// second parameter is sec ??? or field
sectionDisplay( true, crmForm.cpdc_riskweightedvalue);
}
Did you try Force Submit?
Xrm.Page.getAttribute(fieldName).setSubmitMode("always");
I found a script for searching and selecting a specific text from a dynamic text box
But the problem is it is AS2
I started Flash by only studying AS3 so i have no idea on how to convert AS2 to AS3
Pls someone help me :)
finder.onRelease = function() {
Selection.setFocus("_root.textInstance");
var inputterString:String = _root.inputter
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, 0);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
Selection.setSelection(textStart, textEnd);
} else {
Selection.setSelection(0, 0);
}
_root.textEnd = textEnd;
};
findNext.onRelease = function() {
Selection.setFocus("_root.textInstance");
var inputterString:String = _root.inputter;
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, _root.textEnd);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
Selection.setSelection(textStart, textEnd);
} else {
Selection.setSelection(0, 0);
}
_root.textEnd = textEnd;
}
It's not as bad as you might think, but what are finder and findNext - buttons? These are callbacks which can be created by
finder.addEventListener(MouseEvent.MOUSE_UP, finderCallback);
// somewhere else in the code
private function finderCallback(e:MouseEvent):void {
// code here
// anything like _root.<varName> references something on the main file,
// so this just has to be something you can access in the funciton
}
OK, this should be it. I made some assumptions about root.textInstance and the buttons.
import flash.events.MouseEvent;
function onFinderClicked(event:MouseEvent):void{
stage.focus = root.textInstance;
root.textInstance.selectable = true;
var inputterString:String = root.inputter
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, 0);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
root.textInstance.setSelection(textStart, textEnd);
} else {
root.textInstance.setSelection(0, 0);
}
root.textEnd = textEnd;
};
function onFindNextClicked(event:MouseEvent):void{
stage.focus = root.textInstance;
root.textInstance.selectable = true;
var inputterString:String = root.inputter;
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, root.textEnd);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
root.textInstance.setSelection(textStart, textEnd);
} else {
root.textInstance.setSelection(0, 0);
}
root.textEnd = textEnd;
}
finder.addEventListener(MouseEvent.CLICK, onFinderClicked);
findNext.addEventListener(MouseEvent.CLICK, onFindNextClicked);