How to use the property of an object for a variable? - javascript

I'm trying to get the var dir= director to refer to the property "director":"Jean Rouch and Edgar Morin.", How can I do that? I'm new to Javascript, so pardon me if I don't use the right terms.
var myFavoriteDocumentary = {
"name": "Chronicle of a Summer.",
"reldate": "1961.",
"language": "French.",
"director": "Jean Rouch and Edgar Morin.",
"getFavFilm": function () {
return "My favorite non-fiction film is:" + "\n" + this.name + "\n" + "Directed by:" + "\n" + this.director + "\n" + "Year of film:" + "\n" + this.reldate + "\n" + "Language:" + "\n" + this.language;
}
}
console.log(myFavoriteDocumentary.name);
console.log(myFavoriteDocumentary.getFavFilm());
var dir= "director"
function dirFake(dir) {
console.log("The directors are: " + dir);
dir = "Vertov";
console.log( dir + " is not the director" );
}
dirFake(dir);
console.log( dir + " are the true directors!" );

You can use same procedure that you use to console name.
var dir=myFavoriteDocumentary.director;

If you're asking what I think you're asking, just use javascripts bracket or dot notation for objects.
myFavoriteDocumentary.directory;
myFavoriteDocumentary["directory"];

var myFavoriteDocumentary = {
"name": "Chronicle of a Summer.",
"reldate": "1961.",
"language": "French.",
"director": "Jean Rouch and Edgar Morin.",
"getFavFilm": function () {
return "My favorite non-fiction film is:" + "\n" + this.name + "\n" + "Directed by:" + "\n" + this.director + "\n" + "Year of film:" + "\n" + this.reldate + "\n" + "Language:" + "\n" + this.language;
}
}
console.log(myFavoriteDocumentary.name);
console.log(myFavoriteDocumentary.getFavFilm());
var dir = myFavoriteDocumentary.director;
function dirFake(dir) {
console.log("The directors are: " + dir);
dir = "Vertov";
console.log( dir + " is not the director" );
}
dirFake(dir);
console.log( dir + " are the true directors!" );
sorry for the formatting the log shows following result:
Chronicle of a Summer. VM178:11
My favorite non-fiction film is:
Chronicle of a Summer.
Directed by:
Jean Rouch and Edgar Morin.
Year of film:
1961.
Language:
French. VM178:12
The directors are: Jean Rouch and Edgar Morin. VM178:17
Vertov is not the director VM178:19
Jean Rouch and Edgar Morin. are the true directors!
Hope that answers your question.

Related

Post response from Fedex stripped XML tags in Netsuite

I am using UserEventScript to request fedex with tracking number for asking tracking detail.
var headerObj = [];
headerObj['Content-Type'] = 'text/xml';
headerObj['Accept'] = 'text/xml';
var body =
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:v19=\"http://fedex.com/ws/track/v19\">\n" +
" <soapenv:Header />\n" +
" <soapenv:Body>\n" +
" <v19:TrackRequest>\n" +
" <v19:WebAuthenticationDetail>\n" +
" <v19:ParentCredential>\n" +
" <v19:Key>Your key</v19:Key>\n" +
" <v19:Password>Your password</v19:Password>\n" +
" </v19:ParentCredential>\n" +
" <v19:UserCredential>\n" +
" <v19:Key>Your key</v19:Key>\n" +
" <v19:Password>Your password</v19:Password>\n" +
" </v19:UserCredential>\n" +
" </v19:WebAuthenticationDetail>\n" +
" <v19:ClientDetail>\n" +
" <v19:AccountNumber>Your ac no.</v19:AccountNumber>\n" +
" <v19:MeterNumber>Your meter no.</v19:MeterNumber>\n" +
" </v19:ClientDetail>\n" +
" <v19:TransactionDetail>\n" +
" <v19:CustomerTransactionId>Track By
Number_v19</v19:CustomerTransactionId>\n" +
" <v19:Localization>\n" +
" <v19:LanguageCode>EN</v19:LanguageCode>\n" +
" <v19:LocaleCode>US</v19:LocaleCode>\n" +
" </v19:Localization>\n" +
" </v19:TransactionDetail>\n" +
" <v19:Version>\n" +
" <v19:ServiceId>trck</v19:ServiceId>\n" +
" <v19:Major>19</v19:Major>\n" +
" <v19:Intermediate>0</v19:Intermediate>\n" +
" <v19:Minor>0</v19:Minor>\n" +
" </v19:Version>\n" +
" <v19:SelectionDetails>\n" +
" <v19:CarrierCode>FDXE</v19:CarrierCode>\n" +
" <v19:PackageIdentifier>\n" +
" <v19:Type>TRACKING_NUMBER_OR_DOORTAG</v19:Type>\n" +
" <v19:Value>992959690382</v19:Value>\n" +
" </v19:PackageIdentifier>\n" +
" <v19:ShipmentAccountNumber />\n" +
" <v19:SecureSpodAccount />\n" +
" </v19:SelectionDetails>\n" +
" <v19:ProcessingOptions>INCLUDE_DETAILED_SCANS</v19:ProcessingOptions>\n" +
" </v19:TrackRequest>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>"
var resoponse = https.post({
url: 'https://ws.fedex.com:443/web-services',
body: body,
headers:headerObj
});
And the response.body i got is like this.
SUCCESSSUCCESStrck0Request was successfully processed.Request was successfully processed.Track By Number_v19ENUStrck1900SUCCESSSUCCESStrck0Request was successfully processed.Request was successfully processed.falsefalse0SUCCESStrck0Request was successfully processed.Request was successfully processed.9929596903822459294000~992959690382~FX2021-03-21T00:00:00ARArrived at FedEx locationMEMPHISTNUSUnited StatesfalseNo scheduled delivery date available at this time.EDDUNAVAILABLEFDXEFedEx ExpressSHIPPER_REFERENCEB2003217, STAR DIAM LTDINTERNATIONAL_PRIORITYInternational PriorityIPLB1.013123INLB1.0FEDEX_BOXFedEx Box1100AWBDELIVER_WEEKDAYDeliver WeekdayOTHERDUTIES_AND_TAXESRECIPIENT_ACCOUNTRecipientTRANSPORTATIONSHIPPER_ACCOUNTShipperHUNGHOM,HKHong Kong SAR, ChinafalseACTUAL_PICKUP2021-03-20T14:39:00+08:00SHIP2021-03-20T00:00:00ACTUAL_TENDER2021-03-20T14:39:00+08:00ATLANTA,GAUSUnited Statesfalse00ON_DELIVERYON_EXCEPTIONON_ESTIMATED_DELIVERYINDIRECT_SIGNATURE_RELEASEINELIGIBLEREDIRECT_TO_HOLD_AT_LOCATIONPOSSIBLY_ELIGIBLEREROUTEINELIGIBLERESCHEDULEINELIGIBLE2021-03-21T08:19:00-05:00ARArrived at FedEx location
MEMPHISTN38118USUnited Statesfalse
FEDEX_FACILITY2021-03-20T23:17:00-08:00DPDeparted FedEx location
ANCHORAGEAK99502USUnited Statesfalse
FEDEX_FACILITY2021-03-20T21:58:00-08:00ARArrived at FedEx location
ANCHORAGEAK99502USUnited Statesfalse
FEDEX_FACILITY2021-03-21T04:35:00+08:00ITIn transit
CHEK LAP KOK300HKHong Kong SAR, Chinafalse
FEDEX_FACILITY2021-03-20T18:09:00+08:00DPLeft FedEx origin facility
TSUEN WAN230HKHong Kong SAR, Chinafalse
ORIGIN_FEDEX_FACILITY2021-03-20T14:39:00+08:00PUPicked up
TSUEN WAN230HKHong Kong SAR, Chinafalse
PICKUP_LOCATION
Actually, it matches with the normal result i got from postman, but it is unreadable.
What i should do to transfer the above one to be a normal json format or xml format? Or how can i get the exactly value from the above response?
You are not showing how you get that body but I suspect you are just logging it.
What the FedEx API returns is xml. If you log that Netsuite doesn't escape the tags for you so it will look just like that in the log. If you view the log and inspect the details you should see all the tags.
to get NS to escape that for you try:
log.debug({
title:'FedEx Response',
details:xml.escape({xmlText:resp.body})
});
Then you can use code like that below to extract the info you are looking for:
var xmlDocument = xml.Parser.fromString({
text: resp.body
});
var ref = xml.XPath.select({
node: xmlDocument,
xpath: '//ns:TrackingNumber' /* or maybe //nlapi:TrackingNumber or //TrackingNumber */
});
Once you have the full xml by escaping the response you can see the namespaces used in the response. I think the first form is what you'll use but you may need the nlapi: form if the prefix xmlns prefix for ns is also the default namespace.

Poem (random words) generator: How can I get each paragraph to display a different set of random words? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm working on a little practice project that should generate poems. I created a couple of arrays full of different types of words, which I'm then grabbing randomly and adding into paragraphs. It's working, but not how I would like it to.
Since each "phrase" variable is pulling from the same set of randomly selected words, the poems are all repetitive. Whatever random noun is selected will appear in each noun slot, each random verb appears in every verb slot etc.
What I want to happen is: each slot will generate a different random word from the array. If a two of the same words are coincidentally selected at random, that's ok.
For now each type of words selected randomly once, and repeated along all the sentences.
What can I do for i't will selected randomly any time?
Here's the code.
function makeAPoem() {
var nouns = ["cat", "crow", "snow", "home", "boy", "raven", "tree", "moon", "night", "day", "winter", "heart", "angel", "madam", "darkness", "chamber", "lady", "bird", "person", "eye", "darkness", "air"];
var verbs = ["ran", "felt", "fell", "focused", "looked", "stared", "sat", "sighed", "blew", "whimpered", "embraced", "hugged"];
var articles = ["a", "the"];
var adjectives = ["shiny", "sad", "cold", "cheerfully", "sweet", "evil"];
var pronouns = ["I", "we", "you", "they", "she", "it", "he"];
var randNoun = Math.floor(Math.random() * nouns.length);
var randVerb = Math.floor(Math.random() * verbs.length);
var randArticle = Math.floor(Math.random() * articles.length);
var randAdjective = Math.floor(Math.random() * adjectives.length);
var randPronoun = Math.floor(Math.random() * pronouns.length);
var phrase1 = pronouns[randPronoun] + " " + verbs[randVerb] + " " + adjectives[randAdjective];
var phrase2 = articles[randArticle] + " " + nouns[randNoun] + " " + verbs[randVerb] + " " + adjectives[randAdjective];
var phrase3 = pronouns[randPronoun] + " " + verbs[randVerb] + ". " + articles[randArticle] + " " + nouns[randNoun] + " " + verbs[randVerb] + " " + adjectives[randAdjective];
var phrase4 = articles[randArticle] + " " + nouns[randNoun] + " " + verbs[randVerb] + " " + adjectives[randAdjective];
var phrase5 = pronouns[randPronoun] + " " + verbs[randVerb];
document.getElementsByClassName('poem')[0].innerHTML = phrase1;
document.getElementsByClassName('poem')[1].innerHTML = phrase2;
document.getElementsByClassName('poem')[2].innerHTML = phrase3;
document.getElementsByClassName('poem')[3].innerHTML = phrase4;
document.getElementsByClassName('poem')[4].innerHTML = phrase5;
}
<div id="poemBox">
<div id="edgar">
<img src="https://cdn.britannica.com/52/76652-050-F4A6B093/Edgar-Allan-Poe.jpg" width="150px" alt="avatar">
<p>Press the button below for a poem from Poe.</p>
<button onclick="makeAPoem()">Go</button>
</div>
<div id="poetry">
<p class="poem"></p>
<p class="poem"></p>
<p class="poem"></p>
<p class="poem"></p>
<p class="poem"></p>
</div>
In the Screenshot example here, every occurrence of a random adjective is using "sweet". Every random verb is "focused" and so on.
Right now you generate any word type just once.
Just generate the randoms before any phase
function makeAPoem() {
var nouns = ["cat", "crow", "snow", "home", "boy", "raven", "tree", "moon", "night", "day", "winter", "heart", "angel", "madam", "darkness", "chamber", "lady", "bird", "person", "eye", "darkness", "air"];
var verbs = ["ran", "felt", "fell", "focused", "looked", "stared", "sat", "sighed", "blew", "whimpered", "embraced", "hugged"];
var articles = ["a", "the"];
var adjectives = ["shiny", "sad", "cold", "cheerfully", "sweet", "evil"];
var pronouns = ["I", "we", "you", "they", "she", "it", "he"];
function randNoun(){return nouns[Math.floor(Math.random() * nouns.length)]}
function randVerb(){return verbs[Math.floor(Math.random() * verbs.length)]}
function randArticle(){return articles[Math.floor(Math.random() * articles.length)]}
function randAdjective(){return adjectives[Math.floor(Math.random() * adjectives.length)]}
function randPronoun(){return pronouns[Math.floor(Math.random() * pronouns.length)]}
var phrase1 = randPronoun() + " " + randVerb() + " " + randAdjective();
var phrase2 = randArticle() + " " + randNoun() + " " + randVerb() + " " + randAdjective();
var phrase3 = randPronoun() + " " + randVerb() + ". " + randArticle() + " " + randNoun() + " " + randVerb() + " " + randAdjective();
var phrase4 = randArticle() + " " + randNoun() + " " + randVerb() + " " + randAdjective();
var phrase5 = randPronoun() + " " + randVerb();
document.getElementsByClassName('poem')[0].innerHTML = phrase1;
document.getElementsByClassName('poem')[1].innerHTML = phrase2;
document.getElementsByClassName('poem')[2].innerHTML = phrase3;
document.getElementsByClassName('poem')[3].innerHTML = phrase4;
document.getElementsByClassName('poem')[4].innerHTML = phrase5;
}
<div id="poemBox">
<div id="edgar">
<img src="https://cdn.britannica.com/52/76652-050-F4A6B093/Edgar-Allan-Poe.jpg" width="150px" alt="avatar">
<p>Press the button below for a poem from Poe.</p>
<button onclick="makeAPoem()">Go</button>
</div>
<div id="poetry">
<p class="poem"></p>
<p class="poem"></p>
<p class="poem"></p>
<p class="poem"></p>
<p class="poem"></p>
</div>

BIRT (maximo data): overloaded fetch script in scripted dataSet

I've inherited a BIRT .rptdesign that isn't returning any records in "preview results." There is one open script involved, as well as a fetch script that has approximately 5 more sql queries inside of it. Much of what I have tried for solutions involves breaking out these queries involved in the fetch script into their own dataSet, and then relating them to the open script (alternatively I've tried forming a joint data set, with no luck). Even after taking out a small query from the fetch script, I'm not able to generate records in result preview. I tried to upload an image of the layout, but don't have the reputation to do so...Please let me know if you need the design file to help visualize where everything is landing!
Open script:
maximoDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), this.getName());
maximoDataSet.open();
var sqlText = new String();
var printed = params["Printed"].toUpperCase().replace("Y","1");
var printed1 = printed.replace("N","0");
var where = new String(params["where"]);
if (params["Printed"].value)
where += " and workorder.em_printed = '" + printed1 + "' ";
// Add query to sqlText variable.
sqlText = "select workorder.wonum, workorder.workorderid as workorderid1, (select min(w2.workorderid) from maximo.workorder w2 where w2.istask=1 and w2.parent=workorder.wonum and w2.siteid=workorder.siteid) as workorderid, "
+ " workorder.pmnum as pmnum, workorder.targstartdate, workorder.siteid, workorder.description as wdesc, workorder.worktype, a.assetnum, a.description as adesc, a.em_relaymajor, a.em_relayminor, "
+ " workorder.location, l.description as ldesc, a.em_circuit, a.em_manfmodl, a.serialnum, j.em_craft, a.assetuid, "
+ " (select al.description from alndomain al where al.value=j.em_craft and al.domainid='EM_CRAFT') as cdesc, "
+ " (select wt.wtypedesc from maximo.worktype wt where wt.worktype=workorder.worktype) as wtdesc "
+ " from maximo.workorder "
+ " left outer join maximo.asset as a on a.assetnum=workorder.assetnum and a.siteid=workorder.siteid "
+ " left outer join maximo.jobplan as j on j.jpnum=workorder.jpnum and j.pluscrevnum=workorder.pluscjprevnum "
+ " left outer join maximo.locations as l on l.location=workorder.location and l.siteid=workorder.siteid"
// Include the Maximo where clause
+ " where workorder.istask=0 and workorder.status='INPRG' and workorder.siteid='EM' and " + where
;
maximoDataSet.setQuery(sqlText);
Fetch Script:
if (!maximoDataSet.fetch())
return (false);
// Add a line for each output column
// The specific get method should match the data type of the output column.
row["wonum"] = maximoDataSet.getString("wonum");
row["workorderid"] = maximoDataSet.getString("workorderid");
row["workorderid1"] = maximoDataSet.getString("workorderid1");
row["wdesc"] = maximoDataSet.getString("wdesc");
row["worktype"] = maximoDataSet.getString("worktype");
row["assetnum"] = maximoDataSet.getString("assetnum");
row["location"] = maximoDataSet.getString("location");
row["adesc"] = maximoDataSet.getString("adesc");
row["ldesc"] = maximoDataSet.getString("ldesc");
row["em_circuit"] = maximoDataSet.getString("em_circuit");
row["em_manfmodl"] = maximoDataSet.getString("em_manfmodl");
row["serialnum"] = maximoDataSet.getString("serialnum");
row["em_craft"] = maximoDataSet.getString("em_craft");
row["cdesc"] = maximoDataSet.getString("cdesc");
row["wtdesc"] = maximoDataSet.getString("wtdesc");
row["pmnum"] = maximoDataSet.getString("pmnum");
row["siteid"] = maximoDataSet.getString("siteid");
row["assetuid"] = maximoDataSet.getString("assetuid");
row["em_relaymajor"] = maximoDataSet.getString("em_relaymajor");
row["em_relayminor"] = maximoDataSet.getString("em_relayminor");
row["targstartdate"] = maximoDataSet.getTimestamp("targstartdate");
// Long Description
longDescDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "longDescDataSet");
longDescDataSet.open();
longDescSQL = "select longdescription.ldtext "
+ "from longdescription "
+ "where longdescription.ldownertable='WORKORDER' and longdescription.ldownercol='DESCRIPTION' "
+ "and longdescription.ldownercol='DESCRIPTION' "
+ "and longdescription.ldkey=?";
longDescDataSet.setQuery(longDescSQL);
longDescDataSet.setQueryParameterValue(1, maximoDataSet.getString("workorderid"));
if(longDescDataSet.fetch()) {
row["longdesc"] = longDescDataSet.getString("ldtext");
}
longDescDataSet.close();
// End Long Description
// Last Major
lastmajorDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "lastmajorDataSet");
lastmajorDataSet.open();
lastmajorSQL = "select workorder.wonum as wn1, workorder.workorderid as wid1, workorder.description as d1, p.frequency as f1, p.frequnit as fu1, "
+ "p.lastcompdate as lc1, p.extdate as e1, p.nextdate as n1, workorder.targstartdate as tsd1 "
+ "from workorder "
+ "join pm as p on p.pmnum=workorder.pmnum and p.siteid=workorder.siteid "
+ "where workorder.istask = 0 and workorder.actfinish = (select max(w1.actfinish) from maximo.workorder as w1 where w1.wonum=workorder.wonum and w1.siteid=workorder.siteid) "
+ "and workorder.worktype = 'MAJPM' and workorder.assetnum=? and workorder.siteid=? ";
lastmajorDataSet.setQuery(lastmajorSQL);
lastmajorDataSet.setQueryParameterValue(1, maximoDataSet.getString("assetnum"));
lastmajorDataSet.setQueryParameterValue(2, maximoDataSet.getString("siteid"));
if(lastmajorDataSet.fetch()) {
row["wn1"] = lastmajorDataSet.getString("wn1");
row["wid1"] = lastmajorDataSet.getString("wid1");
row["d1"] = lastmajorDataSet.getString("d1");
row["f1"] = lastmajorDataSet.getString("f1");
row["lc1"] = lastmajorDataSet.getTimestamp("lc1");
row["fu1"] = lastmajorDataSet.getString("fu1");
row["e1"] = lastmajorDataSet.getTimestamp("e1");
row["n1"] = lastmajorDataSet.getTimestamp("n1");
row["tsd1"] = lastmajorDataSet.getTimestamp("tsd1");
}
lastmajorDataSet.close();
// End Last Major
// Last Major Initials
lastmajorIDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "lastmajorIDataSet");
lastmajorIDataSet.open();
lastmajorISQL =" WITH x(key, val, rnum) AS "
+ " (SELECT refwo, em_initials, row_number() over(partition by refwo) "
+ " from maximo.labtrans as labtrans "
+ " join maximo.person as person on person.personid=labtrans.laborcode where labtrans.refwo='" + row["wn1"] + "' and labtrans.siteid=?), "
+ " y(key, str, cnt, cnt_max) AS "
+ " ( SELECT key, VARCHAR('', 1000), 0, MAX(rnum) "
+ " FROM x "
+ " GROUP BY key "
+ " UNION ALL "
+ " SELECT y.key, y.str || RTRIM(CHAR(x.val)) || ',', y.cnt + 1, y.cnt_max "
+ " FROM x, y "
+ " WHERE x.key = y.key AND "
+ " x.rnum = y.cnt + 1 AND "
+ " y.cnt < y.cnt_max ) "
+ " SELECT key, str "
+ " FROM y "
+ " WHERE y.cnt = y.cnt_max ";
lastmajorIDataSet.setQuery(lastmajorISQL);
//lastmajorIDataSet.setQueryParameterValue(1, lastmajorDataSet.getString("wn1"));
lastmajorIDataSet.setQueryParameterValue(1, maximoDataSet.getString("siteid"));
if(lastmajorIDataSet.fetch()) {
row["str"] = lastmajorIDataSet.getString("str");
}
lastmajorIDataSet.close();
// End Last Major Initials
// Last Major Long Description
LMlongDescDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "LMlongDescDataSet");
LMlongDescDataSet.open();
LMlongDescSQL = "select longdescription.ldtext as ldtext1 "
+ "from longdescription "
+ "where longdescription.ldownertable='WORKORDER' and longdescription.ldownercol='DESCRIPTION' "
+ "and longdescription.ldkey=" + row["wid1"];
LMlongDescDataSet.setQuery(LMlongDescSQL);
//LMlongDescDataSet.setQueryParameterValue(1, lastmajorDataSet.getString("wid1"));
if(LMlongDescDataSet.fetch()) {
row["longdesc1"] = LMlongDescDataSet.getString("ldtext1");
}
LMlongDescDataSet.close();
// End Last Major Long Description
// Last Minor
lastminorDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "lastminorDataSet");
lastminorDataSet.open();
lastminorSQL = "select workorder.wonum as wn2, workorder.workorderid as wid2, workorder.description as d2, p.frequency as f2, p.frequnit as fu2, "
+ "p.lastcompdate as lc2, p.extdate as e2, p.nextdate as n2, workorder.targstartdate as tsd2 "
+ "from workorder "
+ "join pm as p on p.pmnum=workorder.pmnum and p.siteid=workorder.siteid "
+ "where workorder.istask = 0 and workorder.actfinish = (select max(w1.actfinish) from maximo.workorder as w1 where w1.wonum=workorder.wonum and w1.siteid=workorder.siteid) "
+ "and workorder.worktype = 'MINPM' and workorder.assetnum=? and workorder.siteid= ? ";
lastminorDataSet.setQuery(lastminorSQL);
lastminorDataSet.setQueryParameterValue(1, maximoDataSet.getString("assetnum"));
lastminorDataSet.setQueryParameterValue(2, maximoDataSet.getString("siteid"));
if(lastminorDataSet.fetch()) {
row["wn2"] = lastminorDataSet.getString("wn2");
row["wid2"] = lastminorDataSet.getString("wid2");
row["d2"] = lastminorDataSet.getString("d2");
row["f2"] = lastminorDataSet.getString("f2");
row["lc2"] = lastminorDataSet.getTimestamp("lc2");
row["fu2"] = lastminorDataSet.getString("fu2");
row["e2"] = lastminorDataSet.getTimestamp("e2");
row["n2"] = lastminorDataSet.getTimestamp("n2");
row["tsd2"] = lastminorDataSet.getTimestamp("tsd2");
}
lastminorDataSet.close();
// End Last Minor
// Last Minor Initials
lastminorIDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "lastminorIDataSet");
lastminorIDataSet.open();
lastminorISQL =" WITH x(key, val, rnum) AS "
+ " (SELECT refwo, em_initials, row_number() over(partition by refwo) "
+ " from maximo.labtrans as labtrans "
+ " join maximo.person as person on person.personid=labtrans.laborcode where labtrans.refwo='" + row["wn2"] + "' and labtrans.siteid=?), "
+ " y(key, str1, cnt, cnt_max) AS "
+ " ( SELECT key, VARCHAR('', 1000), 0, MAX(rnum) "
+ " FROM x "
+ " GROUP BY key "
+ " UNION ALL "
+ " SELECT y.key, y.str1 || RTRIM(CHAR(x.val)) || ',', y.cnt + 1, y.cnt_max "
+ " FROM x, y "
+ " WHERE x.key = y.key AND "
+ " x.rnum = y.cnt + 1 AND "
+ " y.cnt < y.cnt_max ) "
+ " SELECT key, str1 "
+ " FROM y "
+ " WHERE y.cnt = y.cnt_max ";
lastminorIDataSet.setQuery(lastminorISQL);
//lastminorIDataSet.setQueryParameterValue(1, lastminorDataSet.getString("wn2"));
lastminorIDataSet.setQueryParameterValue(1, maximoDataSet.getString("siteid"));
if(lastminorIDataSet.fetch()) {
row["str1"] = lastminorIDataSet.getString("str1");
}
lastminorIDataSet.close();
// End Last Minor Initials
// Last Minor Long Description
LM2longDescDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "LM2longDescDataSet");
LM2longDescDataSet.open();
LM2longDescSQL = "select longdescription.ldtext as ldtext2 "
+ "from longdescription "
+ "where longdescription.ldownertable='WORKORDER' and longdescription.ldownercol='DESCRIPTION' "
+ "and longdescription.ldkey=" + row["wid2"];
LM2longDescDataSet.setQuery(LM2longDescSQL);
//LM2longDescDataSet.setQueryParameterValue(1, lastminorDataSet.getString("wid2"));
if(LM2longDescDataSet.fetch()) {
row["longdesc2"] = LM2longDescDataSet.getString("ldtext2");
}
LM2longDescDataSet.close();
// End Last Minor Long Description
// Asset Long Description
AlongDescDataSet = MXReportDataSetProvider.create(this.getDataSource().getName(), "AlongDescDataSet");
AlongDescDataSet.open();
AlongDescSQL = "select longdescription.ldtext as ldtext3 "
+ "from longdescription "
+ "where longdescription.ldownertable='ASSET' and longdescription.ldownercol='DESCRIPTION' "
+ "and longdescription.ldkey=?";
AlongDescDataSet.setQuery(AlongDescSQL);
AlongDescDataSet.setQueryParameterValue(1, maximoDataSet.getString("assetuid"));
if(AlongDescDataSet.fetch()) {
row["longdesc3"] = AlongDescDataSet.getString("ldtext3");
}
AlongDescDataSet.close();
// End Asset Long Description
myTxn = MXReportTxnProvider.create(this.getDataSource().getName());
myStmt = myTxn.createStatement();
myStmt.setQuery("update workorder set workorder.em_printed = '1' where workorder.em_printed = '0' and workorder.workorderid = ? ");
myStmt.setQueryParameterValue(1,row["workorderid1"]);
//myStmt.setQueryParameterValue(2,"'"+row["siteid"]+"'");
myTxn.save();
return (true);
enter image description here

How to replace multiple values in javascript?

I have some of this Code:
function writeIslamicDate(adjustment) {
var wdNames = new Array("Ahad","Ithnin","Thulatha","Arbaa","Khams","Jumuah","Sabt");
var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir",
"Jumadal Ula","Jumadal Akhira","Rajab","Sha'ban",
"Ramadan","Shawwal","Dhul Qa'ada","Dhul Hijja");
var iDate = kuwaiticalendar(adjustment);
var outputIslamicDate = wdNames[iDate[4]] + ", " + (iDate[5]-1) + " " + iMonthNames[iDate[6]] + " " + iDate[7] + " AH";
return outputIslamicDate;
}
document.write(writeIslamicDate());
Output : Ithnin, 23 Ramadan 1435 AH
?
I want to replace 23 with bengali number ২,৩ ///// or two, three
I watch and try a lot of but couldn't success.. Is there are any to solve this ?
Thanks.
I do like
var someString = (iDate[5]-1) + " " + iMonthNames[iDate[6]] + " " + iDate[7] + " হিজরী";
var outputIslamicDate = somestring.replace(/1/g, "১").replace(/4/g, "৪");
return outputIslamicDate;
but it's not work...
Use regex and the global flag:
str.replace(/word/g, 'word2');

Crossfilter can't filter one dimension by another

jsFiddle of the issue
I'm trying to filter over two dimensions in Crossfilter. I have an array of data that repeats a given object:
{
"bioguide_id" : "O000167",
"first_name" : "Barack",
"last_name" : "Obama",
"party" : "Democrat",
"religion" : "United Church of Christ",
"pac_id" : "C00404145",
"pac_name" : "Mendocino County Democratic Central Committee",
"contribution_count" : 4,
"contribution_sum" : 1264,
"congress" : 110
}
I have the following query to crossfilter working perfectly:
var contributions = data.dimension(function(c) { return c.contribution_sum; });
contributions.top(3).forEach(function(p, i) {
console.log(p.pac_name + " (" + p.congress + ")" + ": $" + p.contribution_sum);
});
However, how can I get the top X contribution_sum's from Y congress? I've attempted the following to no avail:
var congress = data.dimension(function(c) { return c.congress; });
congress.filter(111).group().order(function(c) { return c.contribution_sum; }).top(3).forEach(function(p, i) {
console.log(p.pac_name + " (" + p.congress + ")" + ": $" + p.contribution_sum);
});
Any thoughts on why?
I believe you will want to filter on your 'congress' dimension and then ask for the top members of your 'contribution_sum' dimension like:
var congress = data.dimension(function(c) { return +c.congress; });
var contributions = data.dimension(function(c) { return +c.contribution_sum; });
congress.filter(111);
contributions.top(3).forEach(function(p, i) {
console.log(p.pac_name + " (" + p.congress + ")" + ": $" + p.contribution_sum);
});
Complete JSFiddle: http://jsfiddle.net/eWr8Z/5/

Categories