Are there any popular and/or efficient recursive find and replace algorithms? - string

I am currently developing an application that requires the renaming of music files from a variety of variations such as
Artist - Title feat featuring artist, etc
Or
Artist - Title ft featuring artist, etc
Or
Artist - Title (feat. Featuring artist, etc
To
Artist - Title (ft. featuring artist, etc)
I think you get the idea.
My current hacky way to do this:
private void FindAndReplace()
{
try
{
var replaceList = new Dictionary<string, string>
{
{"[", "("},
{"]", ")"},
{"(Official Audio)", ""},
{"(Audio)", ""},
{"OFFICIAL", ""},
{"Official", ""},
{"(Video)", ""},
{"Video)", ""},
{"(video)", ""},
{"video)", ""},
{"(Lyric","" },
{ " Featuring ", " (ft. "},
{",)", ")"},
{" FEAT ", " (FEAT "},
{" Feat ", " (FEAT "},
{" Feat. ", " (FEAT "},
{"(Feat.", "(ft."},
{"(FEAT", "(feat"},
{"( Music",""},
{"(feat", "(ft"},
{"FEAT ", "ft"},
{"( )", ""},
{"()", ""},
{"(|", ""},
{"( |", ""},
{"( )", ""},
{"FT ", "ft. "},
{"Ft ", "ft. "},
{"(Explicit)", ""},
{"ft ", "ft. "},
{" Ft. ", " (ft. "},//[ FT. , (ft. ]
{" FT. ", " (ft. "},//[ FT. , (ft. ]
{" FT", " (ft"},//[ FT, (ft]
{"(FT ", "(ft. "},
{" (ft ", " (ft."},
{" (Ft ", "(ft. "}
};
while (true)
{
var reiterate = false;
foreach (var vari in replaceList)
{
if (FileName.ToLower().Contains(vari.Key.ToLower()))
{
reiterate = true;
}
}
if (reiterate)
foreach (var replaceItem in replaceList.Where(replaceItem => FileName.ToLower().Contains(replaceItem.Key.ToLower()))
)
{
if (FileName.Contains(replaceItem.Key))
FileName = FileName.Replace(replaceItem.Key, replaceItem.Value);
else
FileName = FileName.Replace(replaceItem.Key.ToLower(), replaceItem.Value);
}
if (reiterate) continue;
break;
}
}
catch (Exception ex)
{
}
}
Note that there are a multitude of things that could need fixing in the filename.
I occasionally run into errors with this method and they all stem from the ordering of the replace dictionary. Is there some more efficient and cleaner way to achieve my goal?

You could merge rules by using regular expressions.
e.g
replaceAll("(?i)[\\s\\(]*fe?a?t\\.?[\\s]", " (ft. ")
With this, you could replace all/most of your rules around the 'feature' part.

Related

How to apply threshold and paging on financial series data coming from Alpha Vantage API?

I am using Alpha Vantage API to fetch the financial market data and store it in mongo. My mongo scheme is this:
import * as mongoose from 'mongoose'
export interface Symbol extends mongoose.Document {
code: string,
data_frame: object[],
createdAt: Date,
updatedAt: Date
}
const symbolSchema = new mongoose.Schema({
code:{
type: String,
required: true,
unique: true
},
data_frame:{
type: [Object],
default: {}
},
createdAt:{
type: Date,
default: Date.now()
},
updatedAt:{
type: Date
}
}, {timestamps: true})
export const Symbol = mongoose.model<Symbol>('Symbol', symbolSchema)
This is how data is presented by the Alpha Vantage API:
[
{
"2021-07-02": {
"1. open": "17.39",
"2. high": "17.63",
"3. low": "17.25",
"4. close": "17.43",
"5. adjusted close": "17.43",
"6. volume": "24228000",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0"
},
"2021-07-01": {
"1. open": "16.86",
"2. high": "17.32",
"3. low": "16.82",
"4. close": "17.2",
"5. adjusted close": "17.2",
"6. volume": "39101898",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0"
},
"2021-06-30": {
"1. open": "17.15",
"2. high": "17.46",
"3. low": "17.02",
"4. close": "17.07",
"5. adjusted close": "17.07",
"6. volume": "28807699",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0"
...
]
I'm storing the historical data as an object, just as it comes from the Alpha Vantage API. I'm having trouble skipping and limiting queries from my own API. In other words, I would like to receive only x historical data and be able to apply paging, but I am not able to.
Before, I was using Python, and I saved the Alpha Vantage historical data as an array of numbers. I used the following code snippet and was able to apply the document limitation. Could someone help me?
model.findOne({"code": req.query.code}, {data_frame: {$slice:-req.query.limit}})
.then(obj=>res.json(200, obj.data_frame))
.catch(next)
I tried the following commands without success:
model.aggregate([
{ $match: { "code": req.query.code } },
{ $unwind: "$data_frame" },
{ $limit: 2 }
])
.then(obj=>res.json(200, obj))
.catch(next)
and this..
model.find({"code": req.query.code})
.slice('data_frame', 2)
.then(obj=>res.json(200, obj))
.catch(next)
Basically, you have to update the page every time you go back and next.
let page = 0
let itemsPerPage = 2
model.aggregate([
{ $match: { "code": req.query.code } },
{ $unwind: "$data_frame" },
{ $limit: itemsPerPage },
{ $skip:itemsPerPage*page}
])
.then(obj=>res.json(200, obj))
.catch(next)
Okay, I solved this problem as follows:
My error was storing the data captured by the Alpha Vantage API. So, from these captured data, I applied the following commands, before saving to mongo, as mentioned here:
let documents = []
Object.entries(data["Time Series (Daily)"]).forEach(function (data) {
const index_date = {date: Date.parse(data[0])}
Object.entries(index_date).forEach(([key, value]) => { data[1][key] = value })
documents.push(data[1])
})
Thus, the saved data looked like this:
"data_frame": {
"1. open": "113.41",
"2. high": "114.36",
"3. low": "110.76",
"4. close": "111.28",
"5. adjusted close": "111.28",
"6. volume": "22014500",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0",
"date": 1625097600000
}
And then with the #Hanuman Singh response itself you can limit the query and apply paging.

How to Reference spaces and special characters in express-handlebars node js

after hitting api i get this response which contains spaces and dot by which things are very confusing on how to render them in the handlebars
{
Meta Data: {
1. Information: "Daily Time Series with Splits and Dividend Events",
2. Symbol: "MSFT",
3. Last Refreshed: "2020-02-25 11:20:58",
4. Output Size: "Full size",
5. Time Zone: "US/Eastern"
},
Time Series (Daily): {
2020-02-25: {
1. open: "174.2000",
2. high: "174.8400",
3. low: "169.8800",
4. close: "170.4300",
5. adjusted close: "170.4300",
6. volume: "16881624",
7. dividend amount: "0.0000",
8. split coefficient: "1.0000"
},
2020-02-24: {
1. open: "167.7700",
2. high: "174.5500",
3. low: "163.2300",
4. close: "170.8900",
5. adjusted close: "170.8900",
6. volume: "67892482",
7. dividend amount: "0.0000",
8. split coefficient: "1.0000"
}
}
this is not working
i have tried many things the spaces and the dots are not allowing to render the code in the express handlebars.
please help
router.get('/stock/:name',(req,res)=>
{
let name = req.params.name;
console.log(name);
axios.get(`https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=${name}&apikey=apikey).then((result)=>
{
var newData1 = result.data;
// console.log(newData1);
res.render('home/stock',{newData1});
})
})
how to render it in template
as spaces and dot are present in the response
{{#each newData1}}
{{#each 'Time Series (Daily)'}}
<h5>{{this}}</h5>
{{/each}}
{{/each}}
The Problem
When you use the for-each in Handlebars you need to iterate through an array/list.
But your json (see below) does not contain any arrays/lists.
{
"Meta Data": {
"1. Information": "Daily Time Series with Splits and Dividend Events",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2020-02-25 11:20:58",
"4. Output Size": "Full size",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2020-02-25": {
"1. open": "174.2000",
"2. high": "174.8400",
"3. low": "169.8800",
"4. close": "170.4300",
"5. adjusted close": "170.4300",
"6. volume": "16881624",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
},
"2020-02-24": {
"1. open": "167.7700",
"2. high": "174.5500",
"3. low": "163.2300",
"4. close": "170.8900",
"5. adjusted close": "170.8900",
"6. volume": "67892482",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
}
}
The solution
Below is a json that has arrays/lists.
[
{"Meta Data": [
{"1. Information": "Daily Time Series with Splits and Dividend Events"},
{"2. Symbol": "MSFT"},
{"3. Last Refreshed": "2020-02-25 11:20:58"},
{"4. Output Size": "Full size"},
{"5. Time Zone": "US/Eastern"}
]},
{"Time Series (Daily)": [
{ "2020-02-25": [
{"1. open": "174.2000"},
{"2. high": "174.8400"},
{"3. low": "169.8800"},
{"4. close": "170.4300"},
{"5. adjusted close": "170.4300"},
{"6. volume": "16881624"},
{"7. dividend amount": "0.0000"},
{"8. split coefficient": "1.0000"}
]},
{"2020-02-24": [
{"1. open": "167.7700"},
{"2. high": "174.5500"},
{"3. low": "163.2300"},
{"4. close": "170.8900"},
{"5. adjusted close": "170.8900"},
{"6. volume": "67892482"},
{"7. dividend amount": "0.0000"},
{"8. split coefficient": "1.0000"}
]}
]}
]
So in order to create this new json, we are going to use Node.js (JavaScript) in the backend.
router.get('/stock/:name',(req,res)=>
{
let name = req.params.name;
console.log(name);
axios.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=${name}&apikey=apikey').then((result)=>
{
const newData1 = result.data; // <-------- HERE, I will recommend 'const' instead of 'var' :)
const timeSeriesDaily = newData1["Time Series (Daily)"];
let timeSeriesDailyJSON = [] // <----- timeSeriesDailyJSON will be 'filled' in the for-loop below
for (let dateIndex in timeSeriesDaily) {
let array = timeSeriesDaily[dateIndex];
let newArray = [];
for(let index in array){
newArray.push({
index: index,
value: array[index]
})
}
timeSeriesDailyJSON.push({
date: dateIndex,
array: newArray
});
}
res.render('home/stock', {timeSeriesDailyJSON});
})
})
{{#each timeSeriesDailyJSON}}
<h5>{{date}}</h5>
{{#each array}}
<h5>{{index}}</h5>
<h5>{{value}}</h5>
{{/each}}
{{/each}}

Combining Cypher and GraphQL unable to traverse relationship node

I am new to Neo4j and have been learning for the past few days about using GraphQL with Neo4j through Grandstack. I've been working through this Guide and this Repository working on setting up schemes. I've been working off of the sample neo4j movie database Im attempting to do a basic query where I select the movie by rating using a cypher query as shown below. How ever when testing in the browser I am receiving the following error. Any idea how to fix this or what I am doing wrong thank you
const typeDefs = `
type Movie {
title: String
tagLine: String
released: Int
reviews: [Reviewed]
}
type Reviewed #relation(name: "REVIEWED"){
from: Person
to: Movie
summary: String
rating: String
}
type Person {
name: String
born: Int
actedIn: [Movie] #relation(name: "ACTED_IN",direction:"OUT")
}
type Query {
Movie(title: String ,released: Int, first: Int, offset: Int): [Movie]
ReviewsByScore(score: Int): [Reviewed] #cypher(statement: "MATCH()-[r:REVIEWED]-() WHERE r.rating >= $score RETURN r;")
}
`;
const schema = neo4jgraphql.makeAugmentedSchema({ typeDefs });
In the browser I run the following query
{
ReviewsByScore(score: 100) {
rating
summary
to{
title
}
}
}
and receive the following error.
{ "errors": [
{
"message": "Cannot read property 'value' of undefined",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"ReviewsByScore"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot read property 'value' of undefined",
" at getRelationTypeDirective (/Users/a123456/Desktop/Neo4j Test
Javascript/node_modules/neo4j-graphql-js/dist/utils.js:763:7)",
" at buildCypherSelection (/Users/a123456/Desktop/Neo4j Test
Javascript/node_modules/neo4j-graphql-js/dist/selections.js:184:64)",
" at recurse (/Users/a123456/Desktop/Neo4j Test Javascript/node_modules/neo4j-graphql-js/dist/selections.js:87:33)",
" at buildCypherSelection (/Users/a123456/Desktop/Neo4j Test
Javascript/node_modules/neo4j-graphql-js/dist/selections.js:176:12)",
" at recurse (/Users/a123456/Desktop/Neo4j Test Javascript/node_modules/neo4j-graphql-js/dist/selections.js:87:33)",
" at buildCypherSelection (/Users/a123456/Desktop/Neo4j Test
Javascript/node_modules/neo4j-graphql-js/dist/selections.js:176:12)",
" at customQuery (/Users/a123456/Desktop/Neo4j Test Javascript/node_modules/neo4j-graphql-js/dist/translate.js:575:68)",
" at translateQuery (/Users/a123456/Desktop/Neo4j Test Javascript/node_modules/neo4j-graphql-js/dist/translate.js:518:12)",
" at cypherQuery (/Users/a123456/Desktop/Neo4j Test Javascript/node_modules/neo4j-graphql-js/dist/index.js:146:40)",
" at _callee$ (/Users/a123456/Desktop/Neo4j Test Javascript/node_modules/neo4j-graphql-js/dist/index.js:73:31)"
]
}
}
} ], "data": {
"ReviewsByScore": null } }

ASP.Net MVC : How to customize webgrid pager UI

I need to add some html tag into webgrid pager. webgrid pager is a tfoot tag.
My current grid UI looks like below picture.
but i want my pager look like below picture.
I want to add some image and text along with pager links.
I took help from this website http://www.creativebloq.com/web-design/create-custom-tables-webgrid-9134626
They just replace some tag with more tag this below way
.ToString().Replace("<tfoot><tr><td","<tfoot><tr class='footstuff'><td></td><td style='color: black;'>Records " + firstRecord + " to " + lastRecord + " of " + grid.TotalRowCount + "</td><td></td><td></td><td></td><td")
their full grid code look like.
#MvcHtmlString.Create(
grid.GetHtml(mode: WebGridPagerModes.All, tableStyle: "tranlist", headerStyle: "headerstyle", firstText: "First", lastText: "Last",
columns: grid.Columns(
grid.Column("TranDate", header: "Trans Date", format: #<text>#item.TranDate.ToShortDateString()</text>),
grid.Column("Description", header: "Transaction Description", style: "bigcolumn"), grid.Column("Units", header: "Units", style: "smallcolumn"),
grid.Column("UnitPrice", header: "Unit Price", format: #<text>#item.UnitPrice.ToString("$0.00")</text>, style: "medcolumn"),
grid.Column("Total", canSort: false, header: "Total Price", format: #<text>#{double q = (item.Units * item.UnitPrice);} #q.ToString("$0.00")</text>, style: "medcolumn"),
grid.Column("TransactionID", header: "Action", style: "linkcolumn", canSort: false,
format: #<text> #Html.ActionLink("Edit", "Edit", new { id = item.TransactionID })
| #Html.ActionLink("Delete", "Delete", new { id = item.TransactionID })</text>)))
.ToString().Replace("<tfoot><tr><td","<tfoot><tr class='footstuff'><td></td><td style='color: black;'>Records " + firstRecord + " to " + lastRecord + " of " + grid.TotalRowCount + "</td><td></td><td></td><td></td><td")
)
So I restructured my webgrid code as below but it did not work. In my case nothing has been added in pager area. see my code below and tell me where i made the mistake.
#MvcHtmlString.Create(
grid.GetHtml(
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
firstText: "<<",
previousText: "<",
nextText: ">",
lastText: ">>",
numericLinksCount: 5,
columns:
grid.Columns
(
grid.Column(columnName: "ID", header: "ID", format: #<text>#item.ID</text>,style:"SmallCols"),
grid.Column(columnName: "FirstName", header: "First Name", format: #<text>#item.FirstName</text>,style:"NameColWidth" ),
grid.Column(columnName: "LastName", header: "Last Name", format: #<text>#item.LastName</text>,style:"NameColWidth"),
grid.Column(columnName: "StateName", header: "State Name", format: #<text>#item.StateName</text>,style:"NameColWidth"),
grid.Column(columnName: "CityName", header: "City Name", format: #<text>#item.CityName</text>,style:"NameColWidth"),
grid.Column(header: "IsActive",
format: #<text><input id="select" class="box" name="select"
type="checkbox" #(item.IsActive ? "checked='checked'" : "") value="#item.IsActive" /></text>
, style: "text-center checkbox-width SmallCols")
))
.ToString().Replace("<tfoot><tr><td", "<tfoot><tr class='footstuff'><td></td><td style='color: black;'>Records 1 to 2 of 5 </td><td></td><td></td><td></td><td")
)
looking for help. thanks

Docusign Customer Document Data

With docusign is there a way to send custom data to the document.
The use-case we have is that we are having customers sign an embedded form. We populate all of their data from our Database.
So the main contract is the same but we need to send some values such as contract number, name, address, and price to the document we are having signed. What would be the best way to accomplish this?
I have seen customer tags mentioned for this purpose but it seems like we can only do this in classic view which makes it seem like this will not be a supported feature in the new version.
Update:
I am still at a stand still on this issue.
I have tried doing what was suggested and setting textCustomFields
However, no matter what I pass in the label I set up does not show up.
For example.
I have the Name field on my Document and I also have a Text Field with the Data Label of: contractid
Then I try passing the data in in my envelope as described in the documentation (I have yet to find an example of this anywhere)
string requestBody =
"<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
"<status>sent</status>" +
"<emailSubject>DocuSign API - Embedded Signing example</emailSubject>" +
"<templateId>" + templateId + "</templateId>" +
"<templateRoles>" +
"<templateRole>" +
"<email>" + recipientEmail + "</email>" +
"<name>" + recipientName + "</name>" +
"<roleName>" + templateRole + "</roleName>" +
"<clientUserId>1</clientUserId>" + // user-configurable
"</templateRole>" +
"</templateRoles>" +
"<customFields>" +
"<textCustomFields>" +
"<fieldId>contractid</fieldId>" +
"<name>contractid</name>" +
"<required>true</required>" +
"<show>true</show>" +
"<value>123</value>" +
"</textCustomFields>" +
"</customFields>" +
"</envelopeDefinition>";
The name field shows up correctly in the contract, but that is a custom field predefined by Docusign
However, the contractid field just shows blank as no data has been passed into it.
I even tried adding the information into the call to my view for when I show the embeded contract and that does not do anything either.
I may be going about this the wrong way but so far I can find no good documentation on how to send custom data into the contract via the REST API.
Edit:
Here is a Screen Shot of my setup and I have attempted to add the Text Tabs into both the envelope and the document view request.
I have to say I have worked with Multiple Rest API's including working with Twilio, Phaxio, Twitter and this Rest API implementation seems to be the most confusing I have every ran across as far as what does what
We are working through our DocuSign implementation and are able to do what you are looking for with textTabs added to the signers object. I've attached my POC code in PowerShell that shows the tabs being formatted.
We generate contracts in Word 2013 and use anchors to place everything. The source document will have something like //SIGNATURE// in the text, but before release it is highlighted and changed to white font so the final contract renders nicely in DocuSign.
Results in this (except I chopped out the name and title)
Put your API Key and credentials into the logon function and set up the recipient info at the top. The script creates and sends an envelope with document called "contract.docx"
[string]$recipientEmail = "mr.mann#bluesbrothers.com"
[string]$recipientName = "Mr. Mann"
[string]$recipientFirstName = "Mann"
[string]$recipientTitle = "CEO, Mann, Inc."
function boundry {
[System.Guid]::NewGuid().ToString()
}
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
function logonParams {
[string] $userName = 'YOUR USER NAME'
[string] $password = 'YOUR PASSWORD'
[string] $integratorKey = 'YOUR INTEGRATOR KEY'
#"
{
"Username" : "$userName",
"Password" : "$password",
"IntegratorKey" : "$integratorKey"
}
"#
}
function logon {
[string] $loginURL = 'https://demo.docusign.net/restapi/v2/login_information'
$headers =
#{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="application/json";
}
$r = Invoke-WebRequest -uri $loginURL -headers $headers -method GET
$responseInfo = $r.content | ConvertFrom-Json
$baseURL = $responseInfo.loginAccounts.baseURL
$baseURL
}
function createEnvelope {
param ([string]$contractFile,
[string]$baseURL
)
[string]$boundry = boundry
$headers =
#{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="multipart/form-data; boundary=$boundry";
}
[string]$formData = #"
--$boundry
Content-Type: application/json
{
"status":"sent",
"emailBlurb":"$recipientFirstName, Here is a test contract that I uploaded to DocuSign and routed through their webservice API.",
"emailSubject": "Test Contract $(date)",
"authoritativeCopy" : "true",
"documents": [
{
"name": "$contractFile",
"documentId":"1",
"order":"1"
}
],
"recipients": {
"signers" : [{
"email" : "$recipientEmail",
"name" : "$recipientName",
"title" : "$recipientTitle",
"recipientId":"1",
"tabs" : {
"signHereTabs" : [{
"anchorString" : "//SIGNATURE//"
}],
"fullNameTabs" : [{
"anchorString" : "//SIGNATURE_NAME//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10
}],
"titleTabs" : [{
"anchorString" : "//SIGNATURE_TITLE//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10
}],
"dateTabs" : [{
"anchorString" : "//SIGNATURE_DATE//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10
}],
"textTabs" : [
{
"anchorString" : "//INVOICE_NAME//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10,
"value" : "My Invoice Name",
},
{
"anchorString" : "//INVOICE_ADDRESS1//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10,
"value" : "My Invoice Address 1",
},
{
"anchorString" : "//INVOICE_ADDRESS2//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10,
"value" : "My Invoice Address 2",
},
{
"anchorString" : "//INVOICE_ADDRESS3//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10,
"value" : "My Invoice Address 3",
},
{
"anchorString" : "//INVOICE_EMAIL//",
"font" : "Calibri",
"fontSize" : "Size11",
"anchorYOffset" : -10,
"value" : "somebody#somewhere.com"
}
],
}
}]
}
}
--$boundry
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Transfer-Encoding: base64
Content-Disposition: file; filename="$mainFile";documentid=1
$(encodeFile $contractFile)
--$boundry--
"#
$envelopeURL = "$baseURL/envelopes"
Invoke-WebRequest -uri $envelopeURL -headers $headers -body $formData -method POST
}
$baseURL = logon
createEnvelope "contract.docx" $baseURL
For those using XML and trying to auto fill in the data
string requestBody =
"<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
"<status>sent</status>" +
"<emailSubject>DocuSign API - Embedded Signing example</emailSubject>" +
"<templateId>" + templateId + "</templateId>" +
"<templateRoles>" +
"<templateRole>" +
"<email>" + recipientEmail + "</email>" +
"<name>" + recipientName + "</name>" +
"<roleName>" + templateRole + "</roleName>" +
"<clientUserId>1</clientUserId>" + // user-configurable
"<tabs>" +
"<textTabs>" +
"<text>" +
"<anchorString>follows:</anchorString>" +
"<value>Initial Data Goes</value>" +
"</text>" +
"</textTabs>" +
"</tabs>" +
"</templateRole>" +
"</templateRoles>" +
"</envelopeDefinition>";
Then anywhere in your document you have the words follows: you will have the text show up and you can modify it to display it where you want using other fields.
This would be done through the DocuSign API. You can build a template based on that contract and add the fields that needs data in them. Then when creating the envelope you can set the data that is populated within those fields.
More info can be found here.
EDIT:
Sample code can be found here
Custom Fields refer to Envelope Custom Fields which are an element that can be used to record information about the envelope, help search for envelopes and track information, not for tabs.
You'll want textTab:
<textTabs>
<text>
<anchorIgnoreIfNotPresent>sample string 35</anchorIgnoreIfNotPresent>
<anchorString>sample string 31</anchorString>
<anchorUnits>sample string 34</anchorUnits>
<anchorXOffset>sample string 32</anchorXOffset>
<anchorYOffset>sample string 33</anchorYOffset>
<conditionalParentLabel>sample string 39</conditionalParentLabel>
<conditionalParentValue>sample string 40</conditionalParentValue>
<documentId>sample string 26</documentId>
<pageNumber>sample string 28</pageNumber>
<recipientId>sample string 27</recipientId>
<tabId>sample string 36</tabId>
<templateLocked>sample string 37</templateLocked>
<templateRequired>sample string 38</templateRequired>
<xPosition>sample string 29</xPosition>
<yPosition>sample string 30</yPosition>
<bold>sample string 21</bold>
<font>sample string 20</font>
<fontColor>sample string 24</fontColor>
<fontSize>sample string 25</fontSize>
<italic>sample string 22</italic>
<tabLabel>sample string 19</tabLabel>
<underline>sample string 23</underline>
<concealValueOnDocument>sample string 16</concealValueOnDocument>
<disableAutoSize>sample string 17</disableAutoSize>
<locked>sample string 15</locked>
<maxLength>18</maxLength>
<name>sample string 10</name>
<originalValue>sample string 12</originalValue>
<required>sample string 14</required>
<value>sample string 11</value>
<width>13</width>
<requireAll>sample string 9</requireAll>
<requireInitialOnSharedChange>sample string 7</requireInitialOnSharedChange>
<senderRequired>sample string 8</senderRequired>
<shared>sample string 6</shared>
<validationMessage>sample string 5</validationMessage>
<validationPattern>sample string 4</validationPattern>
<formula>sample string 3</formula>
<height>1</height>
<isPaymentAmount>sample string 2</isPaymentAmount>
</text>
</textTabs>

Resources